#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    6
    Rep Power
    0

    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?

    Thanks In Advanced,

    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() {
            add(lblDate);add(lblShowDate);add(lblSelect);add(lblQuest);
            add(five);add(ten);add(txta);add(txtAns);add(txtAnsType);
            add(txtNumQuest);add(btnStart);add(btnNext);add(btnStop);
            btnStart.addActionListener(this);
            btnNext.addActionListener(this);
            btnStop.addActionListener(this);
            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. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    What's supposed to happen when you execute the program?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    6
    Rep Power
    0
    The Output Will Look Exactly Like This:

    Date the exam was taken: <current date>

    Select the number of question: <radio check>5 <radio check>10

    ------------------------
    |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.
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    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?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    6
    Rep Power
    0
    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.
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    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.

IMN logo majestic logo threadwatch logo seochat tools logo