|
-
I hope somebody will help!
Any tip would be useful.
Thank you in advance.
I have this problem to solve:
Create a Java application that will teach the elementary school student to
learn the multiplication. Use Math.random() to produce two positive numbers
and then display a question: How much is x times y?
let the user enter the answer into a text field. Check the answer and give
one of the following comments:
Responses to correct answers:
Very Good.
Excellent.
Nice Work.
Keep up with the good work.
Response to incorrect answers:
No. Please try again.
Wrong. Try once more.
Don't give up.
No. Keep trying.
Use Math.random() to generate random numbers from 1 to 4 that will be used
to select the appropriate response. Use a switch structure in the paint()
method to issue the responses.
So far I have done this:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ElementarySchool extends JApplet
implements ActionListener
{
private Container c;
JTextField T1;
JPanel Pan,Pan1,Pan2;
JLabel L1, L2, L3,e1,e2,e3,e4;
JButton calc;
String Question, Valuation;
int n1, n2, tot, res;
public void init()
{
c = getContentPane();
c.setLayout(new BorderLayout());
Pan = new JPanel();
Pan.setLayout(new GridLayout(2,1));
c.add(Pan, BorderLayout.NORTH);
Pan1 = new JPanel();
Pan1.setLayout(new GridLayout(2,1));
c.add(Pan1, BorderLayout.CENTER);
Pan2 = new JPanel();
Pan2.setLayout(new GridLayout(2,3));
c.add(Pan2, BorderLayout.SOUTH);
T1 = new JTextField(null, JTextField.CENTER);
T1.setFont(new Font("Verdana", Font.BOLD,20));
String msg = T1.getText();
L1 = new JLabel("Learn the Multiplication!",JLabel.CENTER);
L1.setFont(new Font("Verdana", Font.PLAIN, 32));
for(int x = 0; x < 10; x++)
{
n1 = 1 + (int)(10 * Math.random() - 1);
n2 = 1 + (int)(10 * Math.random() - 1);
tot = n1 * n2;
res = Integer.parseInt(msg);
L2 = new JLabel("How much is " + n1 + " times " + n2 + " ?", JLabel.CENTER);
L2.setFont(new Font("Verdana", Font.ITALIC, 24));
}
if(res == tot)
{L3 = new JLabel("Nice Work!",JLabel.CENTER);
L3.setFont(new Font("Verdana", Font.ITALIC, 24));}
else
{L3 = new JLabel("No. Try again",JLabel.CENTER);
L3.setFont(new Font("Verdana", Font.ITALIC, 24));}
e1 = new JLabel("");
e2 = new JLabel("");
e3 = new JLabel("");
e4 = new JLabel("");
calc = new JButton("Calc");
calc.addActionListener(this);
Pan.add(L1);
Pan.add(L2);
Pan1.add(T1);
Pan2.add(e1);
Pan2.add(L3);
Pan2.add(e2);
Pan2.add(e3);
Pan2.add(calc);
Pan2.add(e4);
}
public void actionPerformed (ActionEvent e)
{
JOptionPane.showMessageDialog(null, "Enter the first number");
}
public void paint(Graphics g)
{
super.paint(g);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks