Question: Introduction Write a program that tests a young childs arithmetic skills. The program tests addition and subtraction. In level 1, it tests only addition of
Introduction
Write a program that tests a young childs arithmetic skills. The program tests addition and subtraction. In level 1, it tests only addition of numbers less than ten whose sum is less than ten. In level 2, it tests addition of arbitrary one-digit numbers. In level 3, it tests subtraction of one-digit numbers with a nonnegative difference.
You will be creating 3 classes for this program. The MathGameRunner class will start off your program and house your main method. The main class is the MathGame class which will contain most of your methods. Every math game has a player, so you will need to create a Player class.
Task #1 Player Class
Every Player has a name and a level. The Player class should have two constructors, one that takes no parameters and initializes the players name to null and the players level to 1. The second constructor takes in two parameters, a String for the name and an int for the level.
This class should contain two accessor methods, the getName method that returns the name and the getLevel method that returns the level.
Task #2 MathGame Class
Every MathGame has a player, random, and scanner object. It will have one constructor that takes no parameters and instantiates the three new objects. The player object will use the constructor that takes no parameters.
This class will contain the following methods: -
Play() :
This is the method that starts the game by rounds. You will be making calls to the other methods in this class (ReadPlayerInformation and PlayRound). You will also ask the user if he would like to play again?
ReadPlayerInformation():
In this method you should prompt the user to enter their name and level, then instantiate a new Player object that takes the name and level as the parameters.
PlayRound():
This method executes a full round of the game according to the level chosen by the user; therefore, you will need to obtain the users level by calling the player objects getLevel method. According to the level returned you will generate Random numbers (according to the original guidelines given in the question) and implement addition or subtraction equations. You will store this correct answer in an int variable called answer.
GetGuess:
In this method you will prompt the user for his guess to the equation given.
If the level is 1 or 2, you will ask him for the sum, but if the level 3, then you will ask him for the difference. This method should return the players guess.
GetResults(int answer):
This method is called at the end of the PlayRound method. When calling this method, you must pass in the original answer to the equation as a parameter. The main function of this method is to call the getGuess method which returns the players guess and compares the original answer to the guess. Based on this comparison a string should be concatenated representing the result.
This method should return the result string.
Task #3 MathGameRunner Class
In this class you will be writing your main method. Create a math game object and call the play method.
Sample Execution 1
What is your name? Mary
At what level do you want to start? (1-3) 1
What is 2 + 4 ? Please enter the sum: 6
Congratulations, Mary! That is correct.
Do you want to play again? (Y/N) y
What is 1 + 7 ? Please enter the sum: 8
Congratulations, Mary! That is correct.
Do you want to play again? (Y/N) n
Sample Execution 2
What is your name? Adam
At what level do you want to start? (1-3) 2
What is 4 + 9 ? Please enter the sum: 11
Please enter the sum: 11
Sorry, Adam. The correct answer is 13
Do you want to play again? (Y/N) y
What is 2 + 7 ? Please enter the sum: 9
Congratulations, Adam! That is correct.
Do you want to play again? (Y/N) y
What is 8 + 6 ? Please enter the sum: 12
Please enter the sum: 11
Sorry, Adam. The correct answer is 14
Do you want to play again? (Y/N) n
Sample Execution 3
What is your name? Noah
At what level do you want to start? (1-3) 3
What is 5 - 2 ? Please enter the difference: 3
Congratulations, Noah! That is correct.
Do you want to play again? (Y/N) y
What is 6 - 4 ? Please enter the difference: 2
Congratulations, Noah! That is correct.
Do you want to play again? (Y/N) y
What is 9 - 6 ? Please enter the difference: 1
Please enter the difference: 2
Sorry, Noah. The correct answer is 3
Do you want to play again? (Y/N) n
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
