The use of computers in education is referred to as computer-assisted instructio
ID: 3757672 • Letter: T
Question
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.
Write the code for the following methods based on the description of each method’s purpose in the comment.
//Given two integers, this method displays a multiplication question to the user.
//For example, if the two numbers are 2 and 9, the method displays
// "What is the result of 2 x 9?" to the user
public static void generateMultiplicationQuestion(int num1, int num2){
}
//This method generates and returns a positive single digit integer using //Math.random() method.
public static int generateRandomSingleDigitNumber() {
}
//This method randomly selects one of four responses:
// Very good!
// Excellent!
// Nice work!
// Keep up the good work!
//informing the user that the answer is correct and returns this response to the //calling method.
//Hint: use a random number generator to randomly select one response.
public static String getResponseToCorrectAnswer(){
}
//This method randomly selects one of four responses:
// No. Please try again.
// Wrong. Try once more.
// Don't give up. Keep trying.
// Incorrect. Please answer again.
//informing the user that the answer is incorrect and returns this response to the //calling method.
//Hint: use a random number generator to randomly select one response.
public static String getResponseToIncorrectAnswer(){
}
//Based on three numbers, this method checks whether the third number is equal to the
//product of the first two numbers.
//If yes, it calls the method getResponseToCorrectAnswer to display a response and //returns true.
// Otherwise, it calls the method getResponseToIncorrectAnswer to display a response
// and returns false.
public static boolean validateMultiplicationAnswer(int num1, int num2, int answer) {
}
After you complete these methods, write a main method that will call these methods to do the following:
Give the user 10 multiplication questions involving two positive single-digit integers.
This can be done by calling the method generateRandomSingleDigitNumber to generate two random positive single-digit integers and then passing these two numbers to the method generateMultiplicationQuestion to display the first question when the application begins execution.
These two steps will be repeated after the user answers the question correctly in order to display the next question.
After each question is given, obtains the answer from the user, and checks whether the answer is correct or not and display corresponding messages to the user.
As long as the answer is incorrect, let the user try the same question repeatedly until the user finally gets it right.
The application also keeps track of the number of questions that the user answered correctly in ONE attempt. Once the user completes 10 questions, the application will display the percentage of questions that the user answered correctly in one attempt. If this percentage is greater than or equal to 70%, the application displays “Congratulations. You are ready to go to the next level!". Otherwise, it displays “Please ask your teacher for extra help.”
Explanation / Answer
import java.util.Scanner;
public class CAL
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int answer;
for(int i = 1; i < 11; i++){
int num1 = generateRandomSingleDigitNumber();
int num2 = generateRandomSingleDigitNumber();
generateMultiplicationQuestion(num1, num2);
answer = input.nextInt();
validateMultiplicationAnswer(num1, num2, answer);
}
}
public static void generateMultiplicationQuestion(int num1, int num2)
{
System.out.println("what's the product for " + num1 + " x " + num2 + "?");
}
public static int generateRandomSingleDigitNumber()
{
return (int)(Math.random()*10);
}
public static String getResponseToCorrectAnswer()
{
//return ("Correct");
int num;
num = (int)(Math.random()*4);
if(num == 3)
{
return("Very good");
}
else if(num == 2)
{
return("Excellent!");
}
else if(num == 1)
{
return("Nice work!");
}
else
{
return("Keep it up the good work!");
}
}
public static String getResponseToIncorrectAnswer()
{
int num;
num = (int)(Math.random()*4);
if(num == 3)
{
return("No. Please try again.");
}
else if(num == 2)
{
return("Wrong. Try once more");
}
else if(num == 1)
{
return("Don't give up. Keep trying.");
}
else
{
return("Incorrect. Please answer again.");
}
}
public static boolean validateMultiplicationAnswer(int num1, int num2, int answer)
{
if(answer == num1 * num2)
{
getResponseToCorrectAnswer();
return true;
}
else
{
getResponseToIncorrectAnswer();
return false;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.