• 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

array variables out of scope-why?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to write this class called GradePoint. For some reason I am not seeing why these few variable,which come from an array, are not being seen by the method setGrade. If anyone can tell me why this is happening I would be very pleased. This is a school project that I have out a lot of time into and would like a little help figuring out what is left to do. GradePoint is called by another class. Thanks for the time...
here is the code
 
Author
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does setGrade look like?
 
James Chegwidden
Author
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, why do you have a method that just creates a Student()? Why not take it out of the method?
 
James Chegwidden
Author
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, would you have to create the Student object first then- create the Array of student objects.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James, see this post for more details on this.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry I haven't had time to look into this for you. Unfortunately, I have a meeting after work today also, so it will be at least another day before I'll be able to try to help.
 
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
For the method that create the Student objects it is one that is required in my specs. setGrade is as follows. It may not be entirely correct either.
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a little hard to tell what is happening here as atleast two of the arrays are from somewhere else.
But this I am able to see: your 'for' loop is assinging different values to the same variables. Which doesn't make much sense to me. So for example 'gradePoints[index]' is being set to a different value each time the loop runs. And will end up containing the value of 'points[i]', where 'i' is '< studentGrades.length'.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another problem is that unless all your arrays are the exact same length, there is a chance you will go out of bounds.
In the 'for' loop you are using the length of 'studentGrades' to iterate through 2 others arrays. Not a safe thing to do.
 
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

Originally posted by William Barnes:
It is a little hard to tell what is happening here as atleast two of the arrays are from somewhere else.
But this I am able to see: your 'for' loop is assinging different values to the same variables. Which doesn't make much sense to me. So for example 'gradePoints[index]' is being set to a different value each time the loop runs. And will end up containing the value of 'points[i]', where 'i' is '< studentGrades.length'.


good point here and I thank you. I had not seen that yet. I put a break; statement in. That should stop the loop when the index of the letterGrade is the same as the gradePoint index. Is that correct? With your second comment. In this case the arrays are the same length throughout. This is just an exercise. Thanks for your time any further comments are appreciated.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic