wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Could someone explain what is wrong with my set methods? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Could someone explain what is wrong with my set methods?" Watch "Could someone explain what is wrong with my set methods?" New topic
Author

Could someone explain what is wrong with my set methods?

kenny gill
Ranch Hand

Joined: Mar 12, 2012
Posts: 54

I'm getting an error with the array grade but I've initialized the project and quizzes array already.




here are the instructions:

These methods should return a boolean to indicate success or failure, depending on if the project or quiz number is out of the bounds of the array. The setProjectScore() and setQuizScore() methods will place the double value into the project or quiz number index of its respective array.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3615
    
  14

Hi Kenny,

I understand that in setProjectScore(), you have to set the value of every element of a to the value of the respective element of projects. This can pose a problem if the projects array is larger than the a array.

So the trick is to first check if projects is larger than a is. If it is, you simply return false. Otherwise, you replace every value of a with the respective value of projects, and then return true.
Yogesh Gnanapraksam
Ranch Hand

Joined: Dec 17, 2009
Posts: 133
int a[0] = 96;


This is not a valid expression.
kenny gill
Ranch Hand

Joined: Mar 12, 2012
Posts: 54

Hello Stephan

The project array is bigger(the size of the array is 15) and I tried to have a return of false but the error didn't seem to go away.



the error states:

Type mismatch: cannot convert from
int to int[]
- Syntax error on token "0", delete this
token
- Syntax error on token "1", delete this
token
jasonhu hu
Greenhorn

Joined: Aug 01, 2012
Posts: 6
kenny gill wrote:
Hello Stephan

The project array is bigger(the size of the array is 15) and I tried to have a return of false but the error didn't seem to go away.



the error states:

Type mismatch: cannot convert from
int to int[]
- Syntax error on token "0", delete this
token
- Syntax error on token "1", delete this
token


******************************************
int a[0] = 96; this expression is wrong , that is ok ? the a array is not declared and is not initialized

but from the wrong message , just convert exception , i feel very strange!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38456
    
  23
Welcome to the Ranch jasonhu hu
Naishadh Parmar
Ranch Hand

Joined: Jun 02, 2011
Posts: 95

The arrays have not been declared and initialized. So they don't even know their length!!!
And you are trying to set the value of the 1st value 96 and 88 and whatever.
First declare both the arrays out of the methods. initialize inside the methods and then set the values.
you can't just think of an array write "int a[0] = 96" and expect it to run
jasonhu hu
Greenhorn

Joined: Aug 01, 2012
Posts: 6
Campbell Ritchie wrote:Welcome to the Ranch jasonhu hu


thanks,i am very happy in the Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could someone explain what is wrong with my set methods?