Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

acceessing an array from another class

 
Valarie Brandt
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all I am having a little problem.
I have a class called Student in that class there is a variable:
public final static char[] GRADES = {'A', 'B', 'C', 'D', 'F'};
I have another class called GradePoint Inside of that class I have a method:
public boolean validateGrades(char tempGrade)throws Exception
{
boolean valid = false;
for(int i = 0; i < GRADES.length; ++i)
{
if (tempGrade == GRADES.Student[i])
{
valid = true;
break;
}
}
return valid;
}
The problem I am having is I need to accept user input and the validate the input...but I can't figure out how to get my method in the GradePoint class to use the array from the Student Class.
PS this is the format the instructor wants us to use.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Valarie Brandt:
I have a class called Student in that class there is a variable:

I have another class called GradePoint Inside of that class I have a method:

Code tags are good. Since GRADES is "public final static", it seems that you could use Student.GRADES[0], Student,GRADES[1], etc
[ April 10, 2004: Message edited by: Marilyn de Queiroz ]
 
Hiep Nguyen
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you can use switch statement for more easy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic