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

Java How to Program (early objects) (10th Edition) Chapter 6, Exercise 6.35 (Com

ID: 3596229 • Letter: J

Question

Java How to Program (early objects) (10th Edition) Chapter 6, Exercise 6.35 (Computer-Assisted Instruction)

The use of computers in education is referred to as computer-assisted instruction (CAI). Write a program that will help an elementary school student learn multiplication. Use a Random object to produce two positive one-digit integers. The program should then prompt the user with a question, such as How much is 6 times 7? The student then inputs the answer. Next, the program checks the student's answer. If it's correct, display the message "Very good!" and ask another multiplication question. If the answer is wrong, display the message "No. Please " and let the student try the same question repeatedly until the student finally gets it right. A separate method should be used to generate each new question. This method should be called once when the application begins execution and each time the user answers the question correctly. (IMPORTANT NOTES: PLEASE USE BRIEF COMMENTS THAT BRIEFLY EXPLAIN THE CODE AS YOU GO AND ONLY CONCEPTS TAUGHT FROM CHAPTERS 1 THROUGH 6 OF THE TEXTBOOK MENTIONED ABOVE.)

Explanation / Answer

Below is your program . Let me know if you have any issue.

Multiplication.java

import java.util.Random;

import java.util.Scanner;

public class Multiplication {

public static void main(String[] args) {

// variable declaration

int correctAns, answer;

String choice;

//Scanner to take inputs

Scanner sc = new Scanner(System.in);

do {

//Calling the method to generate question

correctAns = generateQuestionAndAnswer();

do {

//Asking for guess

System.out.print(" Your answer: ");

answer = sc.nextInt();

//Checking if the answer is right

if (answer == correctAns) {

System.out.println("Very Good! ");

} else {

System.out.println("No Please! Its wrong. Please try again.");

}

} while (answer != correctAns);

//Asking if student wants one more question?

System.out.println("Try another question? [y/n] ");

choice = sc.next();

} while (choice.equalsIgnoreCase("y"));

}

//method to generate question

public static int generateQuestionAndAnswer() {

int num1, num2;

//initializing random variable

Random rand = new Random();

//Generating randoms less than 10

num1 = rand.nextInt(10);

num2 = rand.nextInt(10);

System.out.print("How much is " + num1 + " times " + num2 + "?");

return num1 * num2;

}

}

Output

How much is 7 times 3?
Your answer: 2
No Please! Its wrong. Please try again.

Your answer: 21
Very Good!
Try another question? [y/n]
y
How much is 3 times 2?
Your answer: 3
No Please! Its wrong. Please try again.

Your answer: 6
Very Good!
Try another question? [y/n]
y
How much is 3 times 8?
Your answer: 24
Very Good!
Try another question? [y/n]
n

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