Details:
You will need to write your guessing game according to the following UML.
- The main method should look like the one below, you may not have more than three lines in the main method
public static void main(String[] args){
Scanner userInput = new Scanner(System.in);
GuessingGame myGame = new GuessingGame(userInput);
myGame.startGame();
}
- The GuessingGame constructor should
- take its Scanner parameter and assign it to the keyboardReader instance variable.
- create a new Random object and assign it to the numberGenerator instance variable.
- startGame should
- print an invitation for the user to "think of a number from one to 20."
- inform the user that your program will try to guess the users number.
- generate a random number from 1-20 (inclusive) using the numberGenerator instance variable.
- print this number out as your program's initial guess.
- ask the user if this is the correct number or if it is high or if it is low.
- if the user says the number is high, then call the firstGuessHigh method with that number as a parameter
- if the user says the number is low, then call firstGuessLow and again pass the number as a parameter.
- if the user says the program is right, celebrate and do nothing more (which will end the program.)
- firstGuessHigh
- generate a random number from 1 to the parameter
- ask the user if this is the correct number or if it is high or if it is low.
- if the user says high call secondGuess with 1 as the minGuess and this new number as the max guess
- if the user says low, then call secondGuess and use this value as the minGuess and parameter as maxGuess
- if the user says the program is right, celebrate, mention you got it in two and do nothing more (which will end the program.)
- firstGuessLow should be the inverse of firstGuessHigh, I leave it as an exercise to the students to think about how it works.
- secondGuess
- generate a random number from minGuess to maxGuess
- ask the user if you have it right
- if so, celebrate, mention you got it in three and do nothing more (which will end the program.)
- if not tell the user that the user won.
Additinal restrictions:
To help you get in the habit of good program writing, I am imposing the following additional restrictions on your program.
- You may not have
more than the three lines of code that I gave you in the main method
- You must comment your code. We are starting to get to the point
where you are writing longer programs and doing more on your own. you
will need to start commenting your code so that both you and I know
what you are trying to do. To this end credit in the assignment will be
reservedfor grading your comments.
- Add a readme.txt file as a text file in your submission. Your readme file should contain
- your name
- a brief (one paragraph) description of how
you implemented the project,
- anything that is left undone in the project.
- (you can create a text file using notepad or wordpad on windows or textedit on the mac. - just save it in your project folder)
Submitting:
again zip up your project folder and submit it to me by email.
Make sure that your submitted zip file
contains your first initial and last name as part of the zip file name.