• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

not a statement

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is this statement not a good one.

the errors are
A:\Projects\SRC\JAVA192\Project3\GradePoint.java:60: not a statement
Student[i] aStudent = new Student();
^
A:\Projects\SRC\JAVA192\Project3\GradePoint.java:60: ';' expected
Student[i] aStudent = new Student();
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The compiler is expecting something like:
Type identifier = expression;
and of course the result type of the expression has to be compatible with the Type.
You have:
Student[ i ] aStudent = new Student();
..(Type)....(Ident)..=....(Expr)...
Student[ i ] is not a valid type.
It might be a good way to reference the i'th element of an array named Student, but that doesn't work as a Type.
Now, Student[] without the i could be a valid type, as in "an array of Student objects", but that would not match the result of the expression "new Student()" which is of type Student.
I imagine what you want is to assign a new Student() to each element in array of Students.
So you should declare a new array of the desired size, as in:
Student[] theStudents = new Student[ SIZE ];
and then loop thru them and assign a new Student() to each of these, as in:
theStudents[ i ] = new Student();
OK?
[ October 24, 2002: Message edited by: Dave Landers ]
 
mike hengst
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was a good explanation, bout the best I've read of that idea. Here is my code so that you can see what I am trying to do. instantiateStudent is supposed to fill the Student array I have created at the top of the GradePoint class. I think there are a few other errors as well(maybe you could, or someone hel there). Anyways thanks for any time you spend on this. It is something that is due tomorrow night. Also I don't think that I want direct code but rather an explanation of what I have to do.
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a few comments, based on my "visual compiler" ... javav?


Think about what's happening here - do you really want to call each of these methods twice? I'm not exactly sure what you need to be doing (or so I'm going to claim ) so you need to figure it out.


Since you declared that this method returns a double, you had better make sure that happens, with a "return someDoubleValue;" statement. If you don't want to return something, then don't say that's what yer gonna do.

The compiler does not look at how you use the code, but it does see that it is possible to call this method without having initialized the students array. Might think about rearranging things because of this. Sometimes, if you know better than the compiler, you can get around this message (like initialize the darn thing to some bogus value just to quiet the compiler). But these warnings are worth paying attention to because they usually mean something's amiss in the design/organization of the code.

Ah here's that problem again, but a bit different. One more try and I bet you get it.
What's the name of the array you are assigning to? Is it "Student" or is that the name of the class? Hmmm...
 
mike hengst
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help. I think I am very close. I better be I have to be done with by midnight.
I will post my code for you to digest when I have it complete. Everything compiles now but am having a slight array out of bounds issue. Again thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic