Click to See Complete Forum and Search --> : Java Help on Calculating Score for jeopardy


AzWildcats81
01-16-2005, 03:54 PM
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.

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.

ray326
01-16-2005, 05:34 PM
objSource == btn100Cat1 This is almost never a valid OO comparison. Are you sure it's correct?

AzWildcats81
01-16-2005, 05:49 PM
I'm pretty sure but what do you suggest i use instead?

I'm able to get the program running but when i click btn100Cat1 and then select option button optA and click btnOK, it takes 100 off my score intead of adding it to my score.

buntine
01-16-2005, 07:29 PM
Your not actually adding or removing a specific value from the variable, you are actually explicitely setting it to 100 or -100.

if (optA.getState())
fltCashEarned += 100;
else
fltCashEarned -= 100;

Regards.

AzWildcats81
01-16-2005, 07:38 PM
Thank you for the reply i fixed that. But i still have a problem where the user selects optA but it still subtracts from the total instead of adding to it.

buntine
01-17-2005, 04:07 AM
Can you post your updated code now?

Regards.

ray326
01-17-2005, 05:50 PM
Originally posted by AzWildcats81
I'm pretty sure but what do you suggest i use instead?

I'm able to get the program running but when i click btn100Cat1 and then select option button optA and click btnOK, it takes 100 off my score intead of adding it to my score. Often it needs to be
if (objSource.equals(btn100Cat1)) {...}