aspose file tools*
The moose likes Beginning Java and the fly likes i cant figure out how to use these methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "i cant figure out how to use these methods" Watch "i cant figure out how to use these methods" New topic
Author

i cant figure out how to use these methods

andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
i have no idea what i am doing wrong here. I had the method calculateScore working on its own but when i made the program into a GUI it stopped. it calculates a contestants score (which is an array of doubles) but it gives me an error "calculateScore in Judging cannot be applied to (double[])" and i cant figure out why!

The error is on line 79 of the GUI class

Here are the 3 classes

JUDGING

GUI

TEST


Thanks in advance for helping with my HW that was due 8 days ago
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You still haven't quite understood how to call methods It's ok. Look at your method signature :

What does it tell you ?
1. It doesn't return any value
2. It has no parameter

Your are calling it this way :

The compile error tells you that "calculateScore in Judging cannot be applied to (double[])", and you can see why. You are trying to pass an array of double to a method which has no parameters.

It shouldn't be working in a non-gui application either.


[My Blog]
All roads lead to JavaRanch
andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
in the ULM he showed us it has this method as:
+ calculateScore() : void
so i dont know what i am supposed to do at all, what would you do?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Do you have any documentation with the UML, or only the UML ?
andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
everything is in here:
http://140.192.1.66/ggordon/courses/212/212/homework.dir/program3.html
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

It says it all :
You convert your getData method from Program 1 to the inputScores method. However, it is not needed in this program as the data is read in via the GUI. The method setScores would look like:

So you have to pass the scores which were input by the judges to the setScores method.

The only change in calculateScore is that it doesn't return the actual score but assigns to it to the member of result. The user gets the value of result by calling the method of getResult, which just has one line of code.

After calling setScores, you have to call calculateScore. The result can be retrieved by calling getResult.

So, your logic should looki like :

After that, you have to set the result in the textfield.
andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
I am still getting the error "calculateScore() in Judging cannot be applied to (double[])"
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

My bad. It should be "judge.calculateScore();".

But can't you still figure it out by yourself despite my previous explanation ? You have to understand how methods are used. It is very important. I'm very concerned that even if you finish your assignment, you still won't understand how to call methods.
andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
i thought you had to have score in parenthesis because thats what you are sending to the method... how would it know to pass the array thru without putting in that line of code?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You set the scores by calling setScores. It stores the scores in a private instance variable (this.score = score ). calculateScore is using that variable So you shouldn't have the following in calculateScore :

You have to use Judging's "score" variable instead.
andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
OK i got rid of those 2 lines of code but still having problems... do i even need to have the lines:

and


When i try to just have it print the result it just shows 0.0 even tho when i went thru it with the debugger all the elements of the array were valid, where is the disconnect?

also, when i try to have the JLabel display the result like so:

it tells me "cannot find symbol - constructor JLabel(double)" so how do you have it display a variable?

my brain is fried
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

andrew cassato wrote:when i try to have the JLabel display the result like so:

it tells me "cannot find symbol - constructor JLabel(double)" so how do you have it display a variable?

my brain is fried


Llok at the documentation here

There is no constructor which takes double as argument while creating JLabel. and you are passing in constructor a double value (i.e. result).


Life is easy because we write the source code.....
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I think you have to go through your requirements once again. I'm not going to give you a full solution of your assignment. The assignement says :

actionPerformed :
If all of the scores are within range, it will put the array of scores in Judging by calling setScores. It will then call the method calculateScores of Judging to compute the score. It will then call the method of judging getScores to get the score. It will put the attained score into the textbox for the score.

You can't get more explicit than that. This is were getScores is going to be called. And once again, why are you passing an array to getScores...

it tells me "cannot find symbol - constructor JLabel(double)" so how do you have it display a variable?

1. The assignement assumes that JudgingGUI implements ActionListener. The actionPerformed method should be in JudgingGUI, not in a separate class.
2. Why are you making a new label ?
3. You still can't read a method signature. Look at the API for JLabel. Do you see any constructor with an double[] as a parameter ?
andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
ok thanks for all your help
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: i cant figure out how to use these methods