Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Algorithm for calculating

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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++] );
}

}
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You are comparing Strings using "==" here, which doesn't work. Use equals instead.
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic