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

Develop a Java applet that will help an elementary school student learn multipli

ID: 3529703 • Letter: D

Question

Develop a Java applet that will help an elementary school student learn multiplication. Use the Math.random method or a Random object to produce two positive one-digit integers. The program should then display a question, such as: How much is 6 times 7? This question can be posted anywhere on the applet window you want. You can easily have it go to the status line at the bottom via the showStatus method. The student they types the answer into a JTextField. Next the program checks the student's answer. If the answer is correct, draw the string "Very good!" on the applet and ask another multiplication question. If the answer is wrong, draw the string "No. Please try again." on the applet 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 applet begins execution and each time the user answers the question correctly. All drawing on the applet should be performed by the paint method (usually indirectly through the repaint method).

Explanation / Answer

import java.util.*;

public class Multiply
{
Random randomNumbers = new Random();

int answer; // the correct answer

// ask the user to answer multiplication problems
public void quiz()
{
Scanner input = new Scanner( System.in );
int guess; // the user's guess

createQuestion(); // display the first question

System.out.println( "Enter your answer (-1 to exit):" );
guess = input.nextInt();

while ( guess != -1 )
{
checkResponse( guess );

System.out.println( "Enter your answer (-1 to exit):" );
guess = input.nextInt();
} // end while
} // end method

// prints a new question and stores the corresponding answer
public void createQuestion()
{
// get two random numbers between 0 and 9
int digit1 = randomNumbers.nextInt( 10 );
int digit2 = randomNumbers.nextInt( 10 );

answer = digit1 * digit2;
System.out.printf( "How much is %d times %d? ", digit1, digit2 );
} // end method createQuestion

// checks if the user answered correctly
public void checkResponse( int guess )
{
if ( guess != answer )
System.out.println( "No. Please try again." );
else
{
System.out.println( "Very Good!" );
createQuestion();
} // end else
} // end method checkResponse
} // end class Multiply