Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
January 23rd, 2013, 06:23 PM
 ND04
Registered User

Join Date: Jan 2013
Posts: 6
Time spent in forums: 1 h 59 m 38 sec
Reputation Power: 0
Homework - Applet to Practice Addition Math Problems

On This Java Applet Program. I Got Stuck On The Part Where I Need To Display The Generated Value Of x and y like this and compute for the answer. Could Somebody Help Or Hint Me How To Code This Part, Please?

Code:
```import java.applet.Applet;
import java.util.*;
import java.awt.*;
import java.awt.event.*;

public class Part1 extends Applet implements ActionListener {
Label lblDate=new Label("Date the exam was taken: "),
lblShowDate=new Label(),
lblSelect=new Label("Select the number of questions: "),
lblQuest=new Label("Question No.1 ");
CheckboxGroup chkquestion=new CheckboxGroup();
Checkbox five=new Checkbox("5", chkquestion, false),
ten=new Checkbox("10", chkquestion, false);
Button  btnStart=new Button("Click to start"),
btnNext=new Button("Press for next question"),
btnStop=new Button("Click to stop");
TextArea    txta=new TextArea(5,20);
TextField   txtAns=new TextField(),
txtAnsType=new TextField(),
txtNumQuest=new TextField();
Calendar c= Calendar.getInstance();
int day=c.get(Calendar.DATE);
int month=c.get(Calendar.MONTH)+1;
int year=c.get(Calendar.YEAR);
long startTime, finishTime, diffTime;
int x, y, correct=0, wrong=0, ans, Question,numQuest;
Random rand=new Random();
public void init() {
String date=month+"/"+day+"/"+year;

String start="Start time: "+Long.toString(startTime);
//Spand some Time

//get the new time
finishTime=System.currentTimeMillis();
String finish="Finish time: "+Long.toString(finishTime);
//find the difference
long diffTime=(finishTime-startTime)/1000;
String diff="Duration: "+Long.toString(diffTime);
}
public void actionPerformed(ActionEvent e){
if (five.getState()==true)
{
Question=5;
}
else
{
Question=10;
}
if(e.getSource()==btnStart)
{
startTime=System.currentTimeMillis();
x=rand.nextInt()%100;
y=rand.nextInt()%100;

//Display the x +"+"+y+"=? "

}
}
}```

#2
January 23rd, 2013, 07:52 PM
 NormR
Contributing User

Join Date: Aug 2010
Location: SW Missouri
Posts: 3,589
Time spent in forums: 2 Weeks 3 Days 3 h 18 m 22 sec
Reputation Power: 347
What's supposed to happen when you execute the program?

#3
January 23rd, 2013, 08:28 PM
 ND04
Registered User

Join Date: Jan 2013
Posts: 6
Time spent in forums: 1 h 59 m 38 sec
Reputation Power: 0
The Output Will Look Exactly Like This:

Date the exam was taken: <current date>

------------------------
|Cick to start (btnStart)|
------------------------

Question No.(increase in number from 1~5 or 1~10 base on the <radio checked> rand x "+" rand y "= ?" [txtAns] <++Correct> or <++Wrong>

----------------------------------
|Press for next question (btnNext)|
-----------------------------------

-----------------------
|Click to stop (btnStop)|
-----------------------
Note: When press the stop button after answered all (5) or (10) question. The Text Area Will show the result Of number correct or wrong , and the total time duration that user has taken the test.

----(TextArea)---------
|Duration: 11 seconds |
|No. Corrects: 2 |
|No. Wrong: 3 |
-----------------------
This is the goal ideal of this program.

#4
January 23rd, 2013, 08:32 PM
 NormR
Contributing User

Join Date: Aug 2010
Location: SW Missouri
Posts: 3,589
Time spent in forums: 2 Weeks 3 Days 3 h 18 m 22 sec
Reputation Power: 347
Where will that output be displayed?
What does the user do when the program starts?
What does the program do after the user does something?

What problem are you having with the code? Do you get errors?

#5
January 23rd, 2013, 08:45 PM
 ND04
Registered User

Join Date: Jan 2013
Posts: 6
Time spent in forums: 1 h 59 m 38 sec
Reputation Power: 0
Quote:
 Originally Posted by NormR Where will that output be displayed? What does the user do when the program starts? What does the program do after the user does something? What problem are you having with the code? Do you get errors?

After the Answer was inputted and user click the Press for next question (btn). The program will auto computed and display whether the answer is Correct Or Wrong.
Simultaneously , The program also generate the two new random X and Y for next questions. After (5) or (10) question has been answered.
On The Final Click. Program will Display "DONE" in the Answer box (txtAns).
User can now click the Stop (btnStop). Program will display How long user has used to answered all those questions. And Display the Number of Correct and Wrong Answers in That Big Text Area box.

The Problem I'm having with this program is How To code and get it to display the rand x Value and rand y Value right after the Label: Question No.# : x + y =? [txtAns] Correct.

#6
January 23rd, 2013, 08:56 PM
 NormR
Contributing User

Join Date: Aug 2010
Location: SW Missouri
Posts: 3,589
Time spent in forums: 2 Weeks 3 Days 3 h 18 m 22 sec
Reputation Power: 347
Quote:
 How To code and get it to display the rand x Value and rand y Value right after the Label: Question No.# : x + y =? [txtAns] Correct.

You need to work out a design of where on the frame you want to position the various components. Then find a layout manager that will position the components where you want them. You could use a JLabel to show the question in.

 Viewing: Dev Shed Forums > Programming Languages > Java Help > Homework - Applet to Practice Addition Math Problems