Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

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: 9103
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.
 
rubbery bacon. crispy tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic