Create a Game class. It has a method called public Date getRandomDate

  

Using Java create the following classes below.

Game

Create a Game class. It has a method called public Date getRandomDate() which returns a (pseudo-)randomly-chosen Date between 1600 and 2199, inclusive.

In the public void guessTheDate() method, have the user try to guess the year, then the month, and then the day that is chosen by getRandomDate(). Each time the user is wrong, tell them “higher” or “lower” as appropriate. At any time, if the user types q or Q, the game will quit.

An example game run could look as follows:

New game! Please guess the year (or Q to quit): 1900
Wrong. Higher. Please guess the year: 2000
Wrong. Lower. Please guess the year: 1988
Correct. Please guess the month: -4
Wrong. -4 is not a valid month. Please guess the month: 4
Wrong. Lower. Please guess the month: 2
Correct. Please guess the day: 30
Wrong. 30 is not a valid day for month 2. Please guess the day: 29
Correct. The date was February 29, 1988. This was a Monday.
New game! Please guess the year (or Q to quit): 1950
Wrong. Lower. Please guess the year: 1944
Wrong. Lower. Please guess the year: 1943
Correct. Please guess the month: 13
Wrong. 13 is not a valid month. Please guess the month: 10
Wrong. Higher. Please guess the month: 11
Correct. Please guess the day: 0
Wrong. 0 is not a valid day. Please guess the day: 13
Wrong. Lower. Please guess the day: 5
Wrong. Lower. Please guess the day: 2
Correct. The date was November 1, 1943. This was a Tuesday.
New game! Please guess the year (or Q to quit): q
The game is over. Thank you.

In the public void guessTheBirthdateDay() method, have the user try to guess the day of the week on which a given date fell. Only use dates between January 1, 1900 and January 1 of the current year (just hard code the current year). Use your getRandomDate() method to select a date inside a loop, until it (randomly) picks a date between those listed above. Then ask the user to guess which day of the week it fell on. The user guesses five dates, one guess per date, and then is given a score. An example game run could look as follows:

Date #1: What day of the week was October 5, 1972: Friday
Wrong. It was a Thursday.
Date #2: What day of the week was October 1, 1900: Monday
Correct.
Date #3: What day of the week was March 31, 2000: Friday
Correct.
Date #4: What day of the week was August 10, 2016: Wednesday
Correct.
Date #5: What day of the week was December 25, 1965: Sunday
Wrong. It was a Saturday.
You scored 3 out of 5. Game over.

therefore Create a main method which calls first the guessTheDate() method and then the guessTheBirthdatDay() method.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *