Day 12: Inheritance | 30 Days of Coding | HackerRank | Java Language

**Before watching this make sure that you’ve tried enough**
Language: Java 7

class Student extends Person{
    private int[] testScores;
    private int sum = 0;
    double avrg;

    *   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.
    // Write your constructor here
    Student(String fn,String ln,int id,int []testScore){
        super(fn, ln, id);
        this.testScores = testScore;

    *   Method Name: calculate
    *   @return A character denoting the grade.
    // Write your method here
    char calculate()
        for(int i = 0;i < testScores.length;i++){
            sum += testScores[i];
        avrg = sum / (testScores.length);
        if(avrg >= 90)return 'O';
        else if(avrg >= 80)return 'E';
        else if(avrg >= 70)return 'A';
        else if(avrg >= 55)return 'P';
        else if(avrg >= 40)return 'D';
        else return 'T';


If this solution helped you, please share this with your friends.
And if you have anything to say, let me know in the comment section.
More solutions are coming so Like our Facebook page and Subscribe to our YouTube channel to stay connected.

Leave a Comment