Computer Science  >  QUESTIONS & ANSWERS  >  The Adder game creates a problem from two randomly selected integers Course Hero.pdf (All)

The Adder game creates a problem from two randomly selected integers Course Hero.pdf

Document Content and Description Below

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 Ad ... der 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 a–ects 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]

Last updated: 3 years ago

Preview 1 out of 5 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Preview image of The Adder game creates a problem from two randomly selected integers  Course Hero.pdf document

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Reviews( 0 )

$8.50

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

65
0

Document information


Connected school, study & course


About the document


Uploaded On

Oct 31, 2022

Number of pages

5

Written in

All

Seller


Profile illustration for destinyd
destinyd

Member since 4 years

44 Documents Sold

Reviews Received
6
1
0
0
7
Additional information

This document has been written for:

Uploaded

Oct 31, 2022

Downloads

 0

Views

 65

Document Keyword Tags


$8.50
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·