my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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: 3603
    
  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: 38068
    
  22
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
 
Consider Paul's rocket mass heater.
 
subject: Could someone explain what is wrong with my set methods?
 
Similar Threads
using array list
Confused on how to set-up my getter and setter methods.
More Major Inheritance Stuff.
Can someone explain what is wrong with my set methods?
need help: I'm just not getting how this whole "private" / "public" class definition thing works.