This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array variables out of scope-why?

 
mike hengst
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
James Chegwidden
Author
Ranch Hand
Posts: 201
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does setGrade look like?
 
James Chegwidden
Author
Ranch Hand
Posts: 201
  • 0
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 201
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, would you have to create the Student object first then- create the Array of student objects.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James, see this post for more details on this.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic