Programming in Java II
Not what you're looking for?
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
Purchase this Solution
Solution Summary
A program is developed that prompts the user to guess the outcome of a die throw. A program using a separate class for the die is determined.
Purchase this Solution
Free BrainMass Quizzes
C++ Operators
This quiz tests a student's knowledge about C++ operators.
Excel Introductory Quiz
This quiz tests your knowledge of basics of MS-Excel.
Java loops
This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.
Word 2010: Tables
Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.
Javscript Basics
Quiz on basics of javascript programming language.