The Adder game creates a problem from two randomly selected integers Course Hero.pdf
Question 숤 Answered step-by-step
The Adder game prompts a player for the answer to an addition problem. The Adder game creates a pr
...
The Adder game creates a problem from two randomly selected integers Course Hero.pdf
Question 숤 Answered step-by-step
The Adder game prompts a player for the answer to an addition problem. The Adder game creates a problem from two randomly selected
integers between 0 and 20. Adder allows the player three tries to enter a correct answer. If the correct answer is entered on the rrst try,
the player is awarded 5 points. If the correct answer is entered on the second try, 3 points are awarded. The correct answer on the third try
earns 1 point. If after three tries, the correct answer is still not entered, the player receives no points and the correct answer is displayed.
The game continues until 999 is entered as an answer. At the end of the game, Adder displays the player's score. Application output should
look similar to: How would this be programmed?
Computer Science Engineering & Technology Java Programming
Answer & Explanation Solved by verired expert 숨 Rated 싙 Helpful
The required java code is given below in case of any doubts you can ask me in comments. In case of any doubts you can ask me in
comments.
I have programmed the code and also added comments for you to understand.
Please do understand when you give a feedback and a helpful rating it really aects my career so please do mark me as helpful.
섈 쉋
Step-by-step explanation
섘
Question Answer & Explanation Related Questions Related Textbooks Related Courses
Find study resources 숿7/4/22, 1:23 PM [Solved] The Adder game prompts a player for the answer to an addition problem. The Adder game creates a problem from two randomly selected integers... | Course Hero
https://www.coursehero.com/tutors-problems/Java-Programming/28363539-The-Adder-game-prompts-a-player-for-the-answer-to-an-addition-problem/?justUnlocked=1 2/5
import java.util.Scanner;
public class AdderGame {
// function to generate a random number bewtween max and min values max is exclusive.
public static int randomInteger(int min, int max) {
int nextInteger = (int) ((Math.random() * (max - min)) + min);
return nextInteger;
} /
/ Function to get answer by adding the two numbers
public static int getAnswer(int n1, int n2) {
return n1 + n2;
} /
/ Diver code.
public static void main(String[] args) {
// scanner to read user input
Scanner sc = new Scanner(System.in);
// entry variable to keep user input
int entry = 0;
// score to hold score of user.
int score = 0;
// loop until 999 was entered.
do {
// current points are 5. for the first try.
int currPoint = 5;
// generate 2 random number.
int number1 = randomInteger(0, 21);
int number2 = randomInteger(0, 21);
// display 2 numbers
System.out.print(number1 + " + " + number2 + " = ");
entry = sc.nextInt();
// if entry is not equal to 999
if (entry != 999) {
// if not answer
if (entry != getAnswer(number1, number2)) {
// try 2
// current points are 3
currPoint = 3;
// ask for input from user.
System.out.print("Wrong answer. Enter another answer: ");
entry = sc.nextInt();
// if exit then break from loop
if (entry == 999)
break;
else if (entry != getAnswer(number1, number2)) {
// try 3
// ask again for inputs
currPoint = 1;
System.out.print("Wrong answer. Enter another answer: ");
entry = sc.nextInt();
// if 99 then exit.
if (entry == 999)
break;
// if not correct answer
else if (entry != getAnswer(number1, number2)) {
// current points are 0
currPoint = 0;
// print current answers
System.out.println("Correct Answer is: " + getAnswer(number1, number2));
}
}
} /
/ increase the score.
score += currPoint;
}
} while (entry != 999);
// print the score.
System.out.println("Your score is: " + score);
[Show More]