Skip to content

Instantly share code, notes, and snippets.

@jfsr
Created October 19, 2017 19:30
Show Gist options
  • Save jfsr/c214fcdf0890eb2d66f3d0dce645bdb0 to your computer and use it in GitHub Desktop.
Save jfsr/c214fcdf0890eb2d66f3d0dce645bdb0 to your computer and use it in GitHub Desktop.
Day 12: Inheritance
class Student extends Person{
private int[] testScores;
/*
* Class Constructor
*
* @param firstName - A string denoting the Person's first name.
* @param lastName - A string denoting the Person's last name.
* @param id - An integer denoting the Person's ID number.
* @param scores - An array of integers denoting the Person's test scores.
*/
public Student(String firstName, String lastName, int identification, int[] scores){
super(firstName,lastName,identification);
this.testScores = scores;
}
/*
* Method Name: calculate
* @return A character denoting the grade.
*/
public String calculate(){
double sum = 0;
for(int score : testScores) sum += score;
double avg = sum/testScores.length;
String [][] gradingScale = {{"90","O"},{"80","E"},{"70","A"},{"55","P"},{"40","D"}};
for(String[] tuple:gradingScale){
if(avg >= Integer.parseInt(tuple[0])){
return tuple[1];
}
}
return "T";
}
}
@haroldogtf
Copy link

Interesting solution for not using nested ifs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment