• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Could someone explain what is wrong with my set methods?  RSS feed

 
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.
 
Saloon Keeper
Posts: 10230
216
  • 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.
 
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
 
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!
 
Marshal
Posts: 64494
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch jasonhu hu
 
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
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!