Urgent help needed please!! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Urgent help needed please!!

Hi!!
I need help in writing a program that will help an elimentary school student learn multiplication, using Math.random to produce two positive one-digit integers. The student then types the answer into a text field and the program checks the student's answer, if its correct it displays the string "Very Good" in the browser status bar and generate a new question. If the answer is wrong, it displays the string "Please try again" and lets the student tries the same question repeatedly until he/she gets the right answer.
I have to use "switch" structure to issue four different correct and incorrect responses. And also, i have to use GUI in developing the program.

Any help will be appreciated.
Thanks.

Comments

  • Josh CodeJosh Code Posts: 675Member
    /**
    The following is a console user interface to a very similar program.
    It shouldn't be hard to make a JFrame and get the values from a JTextField and put the comments in a status bar.
    */

    import java.util.*;
    import java.io.*;

    public class ass1
    {
    public static void main(String a[]) throws IOException
    {
    Random r = new Random(System.currentTimeMillis());
    while (true)
    { // loop through questions until the loop is broken with a correct answer
    int n1 = r.nextInt(10), n2 = r.nextInt(10);
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    System.out.println(n1 + "*" + n2 + "=?");
    int answer = Integer.parseInt(reader.readLine().trim());
    if (answer == n1 * n2)
    { // correct
    System.out.println("Very Good");
    break; // get out of the loop
    }
    else // wrong answer
    {
    int responseIndex = r.nextInt(4);
    switch (responseIndex)
    {
    case 0:
    System.out.println(
    "Ask your parents to check if there was led "
    + "paint chips in your crib.");
    break;

    case 1:
    System.out.println(
    "Ask your mom if she smoked or drank alcohol "
    + "while pregnant with you.");
    break;

    case 2:
    System.out.println(
    "Let your teacher know that you need "
    + "lots of extra attention.");
    break;

    case 3:
    System.out.println(
    "Ask your parents to check if there was led "
    + "paint chips in your crib.");
    break;

    }
    }
    }
    }
    }

    : Hi!!
    : I need help in writing a program that will help an elimentary school
    : student learn multiplication, using Math.random to produce two
    : positive one-digit integers. The student then types the answer into
    : a text field and the program checks the student's answer, if its
    : correct it displays the string "Very Good" in the browser status bar
    : and generate a new question. If the answer is wrong, it displays the
    : string "Please try again" and lets the student tries the same
    : question repeatedly until he/she gets the right answer.
    : I have to use "switch" structure to issue four different correct and
    : incorrect responses. And also, i have to use GUI in developing the
    : program.
    :
    : Any help will be appreciated.
    : Thanks.
Sign In or Register to comment.