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

<!DOCTYPE html> Write a program that will help elementary school student learn m

ID: 3667566 • Letter: #

Question

<!DOCTYPE html>

Write a program that will help elementary school student learn multiplication. Use math.random to produce two positive one-digit integers. It should then display a question such:

How much is 5 times 6?

The student then types the answer into a text field. Your program checks a student’s answer. If it is correct the string says.

Very good!

Excellent!

Nice Work!

Keep up the good work!

If the student answers wrong:

No. Please try again.

Wrong. Try once more.

Don’t give up!

No. Keep trying.

Use a random number generation to choose a number from 1 to 4 that will be used to select an appropriate response to each answer. Use a switch statement to issue the responses. Let the student

Students try the same question again repeatedly until they get it right. A separate function should be used to generate each new question. This function should be called once when the script begins execution and each time the user answer the question.

Explanation / Answer

import java.awt.*;

import java.awt.Graphics;

import java.lang.Object;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;

public class NewJApplet extends JApplet implements ActionListener

{

public Graphics brush;

Random rand = new Random();

int number1 = rand.nextInt(10);

int number2 = rand.nextInt(10);

JLabel question = new JLabel("What is " + number1 + " times " + number2 + "?");

JTextField answer = new JTextField(3);

JButton checkAnswer = new JButton("Check Answer");

Font font1 = new Font("Teen", Font.BOLD, 30);

Font font2 = new Font("Teen", Font.ITALIC, 36);

String right = "Very good!!!";

String wrong = "No. Please try again.";

Container con = getContentPane();

public void init()

{

setLayout(new FlowLayout());

con.setBackground(Color.BLUE);

question.setLocation(20, 20);

question.setFont(font1);

con.add(question);

answer.setLocation(20, 40);

con.add(answer);

checkAnswer.setLocation(20, 60);

con.add(checkAnswer);

checkAnswer.addActionListener(new ActionListener()

{

public void paint()

{

brush.setFont(font2);

}

public void actionPerformed(ActionEvent e)

{

int ans = Integer.parseInt(answer.getText());

if(ans == number1 * number2)

{

answer.setText("");

Random rand = new Random();

int number1 = rand.nextInt(9) + 1;

int number2 = rand.nextInt(9) + 1;

brush.drawString(right, 20, 80);

repaint();

validate();

}

else

{

answer.setText("");

brush.drawString(wrong, 20, 80);

repaint();

validate();

}

}

}

);

}

@Override

public void actionPerformed(ActionEvent e)

{

answer.setText("");

Random rand = new Random();

int number1 = rand.nextInt(10);

int number2 = rand.nextInt(10);

}

}

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