• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could someone explain what is wrong with my set methods?

 
kenny gill
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 6128
74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int a[0] = 96;


This is not a valid expression.
 
kenny gill
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49849
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch jasonhu hu
 
Naishadh Parmar
Ranch Hand
Posts: 95
C++ Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch jasonhu hu


thanks,i am very happy in the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic