Java Help on Calculating Score for jeopardy


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Java Help on Calculating Score for jeopardy

  1. #1
    Join Date
    Jan 2005
    Posts
    2

    Java Help on Calculating Score for jeopardy

    When i i want it to add a certain amount to the intCashEarned varable and then display it, it will just subtract tha amount instead. Im using Ready to Program. Here is some example code of what im talking about.

    Code:
    Object objSource = evt.getSource ();
            //Catagory #1 -- $100
            if (objSource == btn100Cat1)
            {
                sndTheme.play ();
                lblQLine1.setText ("What is the capitol of Canada?");
                lblAnsA.setText ("A: Ottawa");
                lblAnsB.setText ("B: Toronto");
                lblAnsC.setText ("C: Vancouver");
                btn100Cat1.setEnabled (false);
                btnOK.setEnabled (true);
                if (optA.getState ())
                    fltCashEarned = 100;
                else
                    fltCashEarned = -100;
            }
    When they select option button A it just subracts 100 dollars instead of adding it ot the total score.

    To view my entire program go here...
    kenigweb.com/JeopardyApplet.java

    you can open it in notepad if you dont have Ready to Program.

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    As far as I can see you only accumulate scores at the ok button click. How about changing the design a bit ?

    Code:
            /Catagory #1 -- $100
            if (objSource == btn100Cat1)
            {
                sndTheme.play ();
                lblQLine1.setText ("What is the capitol of Canada?");
                lblAnsA.setText ("A: Ottawa");
                lblAnsB.setText ("B: Toronto");
                lblAnsC.setText ("C: Vancouver");
                btn100Cat1.setEnabled (false);
                btnOK.setEnabled (true);
                accumulateScore (optA.getState (), 100)     
             }
    .
    .
    .
    . private int accumulateScore(boolean win, int amount) {
        fltScore += (win) ? amount : -amount;
      }
    You should also consider a table driven approach when
    you are dealing w. these armies of buttons.
    eschew obfuscation

  3. #3
    Join Date
    Jan 2005
    Posts
    2
    Can you please explain what i should do abit more? I'm abit confused on how to get this to work,

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    You are doing two things at the same time;
    In the actionPerformed you set the question and options
    and get retrieve the answer, you sure don't give the contestants much time

    WHat you should do was something like this:

    Code:
    define these as applet class variables:
    
    int fltCashEarned;
    CheckBox correct;
    
            if (objSource == btn100Cat1)
            {
                sndTheme.play ();
                lblQLine1.setText ("What is the capitol of Canada?");
                lblAnsA.setText ("A: Ottawa");
                lblAnsB.setText ("B: Toronto");
                lblAnsC.setText ("C: Vancouver");
                btn100Cat1.setEnabled (false);
                btnOK.setEnabled (true);
                correct=optA;    
                fltCashEarned=100;
             }
    then when the ok btn is clicked you check that the
    optionButton that is selected is the same as correct or
    not, and negate the fltCashEarned if not, then you call
    the MoneyEarned (); method.

    in you code the itemStateChanged does nada.
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center