Object Orientation

Moderators: None (Apply to moderate this forum)
Number of threads: 44
Number of posts: 76

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Urgent help needed please!! Posted by MiMi__143 on 23 May 2007 at 8:13 AM
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.
Report
Re: Urgent help needed please!! Posted by Josh Code on 11 Jan 2008 at 9:00 AM
/**
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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.