• 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

acceessing an array from another class

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think you can use switch statement for more easy.
 
reply
    Bookmark Topic Watch Topic
  • New Topic