Created
October 19, 2017 19:30
-
-
Save jfsr/c214fcdf0890eb2d66f3d0dce645bdb0 to your computer and use it in GitHub Desktop.
Day 12: Inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting solution for not using nested ifs.