Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Work programming exercise 3.2, page 108, from the textbook. Name it AddThreeNumb

ID: 3860474 • Letter: W

Question

Work programming exercise 3.2, page 108, from the textbook. Name it AddThreeNumbers. Run the program with different input values. Document the code and use the output model shown for Listing 3.1 on page 77 in the textbook.

3.2 (Game: add three numbers) The program in Listing 3.1, AdditionQuiz.java, gen- erates two integers and prompts the user to enter the sum of these two integers. Revise the program to generate three single-digit integers and prompt the user to enter the sum of these three integers.

Explanation / Answer

import java.util.*; public class MyTest { public static void main(String[] args) { Scanner input = new Scanner(System.in); // random single digit integer int d1 = (int)(Math.random() * 10); int d2 = (int)(Math.random() * 10); int d3 = (int)(Math.random() * 10); // Prompt user to enter the sum of three integers System.out.print( "Please provide the sum of " + d1 + " + " + d2 + " + " + d3 + " = "); int user_answer = input.nextInt(); System.out.println( d1 + " + " + d2 + " + " + d3 + " = " + user_answer + " is " + (d1 + d2 + d3 == user_answer)); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote