Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Algorithm for calculating

 
jonas okwara
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please can Anyone help me. Trying to do an algorithms to calculate score after a jbutton is clicked.


thx

joe
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Svend Rost
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You are comparing Strings using "==" here, which doesn't work. Use equals instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic