Project 7-3: Guessing Game

Project 7-3: Guessing Game
Convert a previous application so it uses classes to organize its code.

Console
Welcome to the Guess the Number Game

++++++++++++++++++++++++++++++++++++

I’m thinking of a number from 1 to 100.

Try to guess it.

Enter number: 50

You got it in 1 tries.

Great work! You are a mathematical wizard.

Try again? (y/n): y

I’m thinking of a number from 1 to 100.

Try to guess it.

Enter number: 50

Way too high! Guess again.

Enter number: 30

Too high! Guess again.

Enter number: 15

Too low! Guess again.

Enter number: 23

Too high! Guess again.

Enter number: 19

Too low! Guess again.

Enter number: 21

Too high! Guess again.

Enter number: 20

You got it in 7 tries.

Not too bad! You’ve got some potential.

Try again? (y/n):

Error! This entry is required. Try again.

Try again? (y/n): x

Error! Entry must be ‘y’ or ‘n’. Try again.

Try again? (y/n): n

Bye – Come back soon!

Specifications
Your instructor should provide you with a starting project.

Create a class named Console, and move all the methods that retrieve and validate user input to that class. These methods can remain static.

Create a class named Game, and move all the methods that display messages and handle user guesses to that class. Adjust these methods so they aren’t static, and use instance variables of the Game class to keep track of numbers, guesses, and so on.

Update the application to use these classes and their methods. Make sure the application functions the same as it did before.

You can leave a response, or trackback from your own site.