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