CS480D Homework Assignment Two

Part I: Guess a number from 1 to 100

{`++++++++++++++++++++++++++++++++++++ 
I'm thinking of a number from 1 to 100. 
Try to guess it. 
Enter number: 50 You got it in 1 tries. Great work! You are a mathematical wizard. 
Try again? (y/n): y 
I'm thinking of a number from 1 to 100. 
Try to guess it. 
Enter number: 50 Way too high! Guess again. 
Enter number: 30 Too high! Guess again. 
Enter number: 15 Too low! Guess again. 
Enter number: 23 Too high! Guess again. 
Enter number: 19 Too low! Guess again. 
Enter number: 21 Too high! Guess again. 
Enter number: 20 You got it in 7 tries. Not too bad! You've got some potential. 
Try again? (y/n): 
Error! This entry is required. Try again. 
Try again? (y/n): x 
Error! Entry must be 'y' or 'n'. Try again. 
Try again? (y/n): n 
Bye - Come back soon! 
Press any key to continue . . . 
`}

Example of Run-time Output Console Welcome

Operation

  • Write a class called GuessGame with all business logics for guess game, and then write a driver called GuessGameApp to test.
  • The application prompts the user to enter an int value from 1 to 100 until the user guesses the random number that the application has generated.
  • The application displays messages that indicate whether the user’s guess is too high or too low.
  • When the user guesses the number, the application displays the number of guesses along with a rating. Then, the application asks if the user wants to play again.

When the user exits the game, the application displays a goodbye message.

Specifications

  • If the user’s guess is more than 10 higher than the random number, the application should say, “Way too high!”
  • If the user’s guess is higher than the random number, the application should say, “Too high!”
  • If the user’s guess is lower than the random number, the application should say, “Too low!”
  • The message that’s displayed when the user gets the number should vary depending on the number of guesses. For example:
    {`Number of guesses Message 
    ================= ======= <=3 Great work! You are a mathematical wizard. 
    >3 and <=7 Not too bad! You've got some potential. 
    >7 What took you so long? Maybe you should take some lessons 
    `}
  • When the user guesses a number, the application should only accept numbers from 1 to 100.
  • When the user responds to the Play Again prompt, the application should only accept a value of “y” or “n”.
  • If the user enters invalid data, the application should display an appropriate error message and prompt the user again until the user enters valid data. The code that’s used to validate data should be stored in separate methods. For example: public static int getIntWithinRange(Scanner sc, String prompt, int min, int max)
  • Use the random method of the java.lang.Math class to generate a random number.
  • Use nextLine() to detect if the user did not enter any and just hit return key in a method that will verify valid entry for y/n. Use Validator examples discussed in the class.
  • Use of meaningful names and comments.
  • Your name (last name, first name), class title and section #, the assignment #, and a brief description of the lab must show up at the top of the source code.
  • There will be no point if your program does not run.

(Continue to next page and see Part II)

Part II: Calculate a circle’s circumference and area

Example of Run-time Output Console (data validations are not showing)

{`
Welcome to the Circle Tester 
Enter radius: 3 
Circumference: 18.85 
Area: 28.27 
Continue? (y/n): y 
Enter radius: 6 
Circumference: 37.7 
Area: 113.1 
Continue? (y/n): n 
Goodbye. You created 2 Circle object(s). 
Press any key to continue . . . 
`}

Operation

  • Write a class called Circle with all business logics for the circle calculation, and then write a driver for testing.
  • The application prompts the user to enter the radius of a circle.
  • If the user enters invalid data, the application displays an appropriate error message and prompts the user again until the user enters valid data. A radius cannot be negative.
  • When the user enters a valid radius, the application calculates and displays the circumference and area of the circle to the nearest 2 decimal places.
  • The application prompts the user to continue.
  • When the user chooses not to continue, the application displays a goodbye message that indicates the number of Circle objects that were created by the application.

Specifications

  • Create a class named Circle to store the data about this circle. This class should contain these constructors and methods:
    {`
    public Circle(double radius) 
    public double getCircumference() 
    public String getFormattedCircumference() 
    public double getArea() 
    public String getFormattedArea() 
    private String formattedRadius() 
    public static int getObjectCount() 
    `}
  • The formulas for calculating circumference and area are: circumference = 2 * pi * radius area = pi * radius2
  • For the value of pi, use the PI constant of the java.lang.Math class.
  • Create a class named CircleApp that gets the user input, creates a Circle object, and displays the circumference and area. The method getFormattedRadius() is called to display the radius; getFormattedCircumference() is called to display the circumference; and getFormattedArea() is called to display the area. They are all displayed as 2 decimal places.
  • Code more static methods in the Validator discussed in the class to validate the data in this application.
  • Code a static method to retrieve the object count data when user entered n for quit.
  • Use of meaningful names and comments.
  • Your name (last name, first name), class title and section #, the assignment #, and a brief description of the lab must show up at the top of the source code.
  • There will be no point if your program does not run.
citation generator
citaion generator
make money online