wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Algorithm for  calculating Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Algorithm for  calculating" Watch "Algorithm for  calculating" New topic
Author

Algorithm for calculating

jonas okwara
Ranch Hand

Joined: Jun 22, 2004
Posts: 58
please can Anyone help me. Trying to do an algorithms to calculate score after a jbutton is clicked.


thx

joe
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Please do not post the same question in multiple forums. Doing so wastes the time of people who may answer a post that has already been answered.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Hi Jonas,

What is it that you wan't to calculate, and what have you made so far ?

You should take a look at the interface java.awt.event.ActionListener

/Svend Rost
jonas okwara
Ranch Hand

Joined: Jun 22, 2004
Posts: 58
Thanks for your reply. The Listener part is not the problem. I have done all that. Please take a look at what I have been trying to crack since Tuesday. I must say that this is neither a class assignment nor a project at work. I passed the scjp last December and the only way I can know my craft is to do a hypothetical project which is why I am doing this. I am not a java programmer yet. When I get there, I will know. Aagain Thx

joe

//Declare listener and add to Radio Button objects
//--------------------------------------------------------
class RadioButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent evt){
Object source = evt.getActionCommand();
if (source.equals( rb1 )) //rb1 is one of my Answers

Scoreclass theScore = new Scoreclass();
theScore.calculateScore(source, position);
position++;
}

}


//===================================================================

Below is my "Scoreclass" class. Essentially what I want to do is to compare
User choices against an Array of equivalent indexes. If the indexes match
then a score is calculated. i have tried with ArrayList but still don't get anywhere.

//==========================================================================

class Scoreclass {
int count = 0;
void calculateScore(Object source, int score ){
String[] buttonC = { "rb1", "rb2", "rb3", "rb4","rb5"};
if( source == buttonC[score ])
System.out.println(buttonC[count++] );
}

}
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112


You are comparing Strings using "==" here, which doesn't work. Use equals instead.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
Don't get me started about those stupid light bulbs.
 
subject: Algorithm for calculating