Develop a program that prompts the user to guess outcome


Questions:

Programming in Java II

Question 1: Develop a program that prompts the user to guess the outcome of a die throw. Then throw a die (using a random number generator) and inform the user if they guessed the correct outcome. Count the number of correct guesses. Develop the program using a separate class for the die. Your program should contain two separate java files, one for the main method and one for your die class. The interaction should be as follows:

Guess the outcome of the die throw (1-6, 0 to quit): 3
The throw of the die was 5, sorry...

Guess the outcome of the die throw (1-6, 0 to quit): 2
The throw of the die was 2, you win!

Guess the outcome of the die throw (1-6, 0 to quit): 8
A die only has six sides...try again...

Guess the outcome of the die throw (1-6, 0 to quit): 0
You guessed correctly 1 time.
Thanks for playing.

The die class must contain (at least) the following methods:

A constructor that initializes the die to some random side.
roll() - sets the die to a random side
getFace() - returns the current value of the die

equals() - returns true when the passed die is equal to the current die
compareTo() - compares two dice returning -1, 0 or 1
toString() - returns the string representation of the current die

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Develop a program that prompts the user to guess outcome
Reference No:- TGS01937768

Now Priced at $20 (50% Discount)

Recommended (96%)

Rated (4.8/5)