Input Format
The locked stub code in your editor calls your Student class constructor and passes it the necessary arguments. It also calls the calculate method (which takes no arguments).
You are not responsible for reading the following input from stdin:
The first line contains , and , respectively. The second line contains the number of test scores. The third line of space-separated integers describes .
Output Format
This is handled by the locked stub code in your editor. Your output will be correct if your Student class constructor and calculate() method are properly implemented.
Inheritance problem solution - 30 days of code HackerRank

Problem solution in Java programming language.

class Student extends Person {
    private int[] testScores;

    Student(String firstName, String lastName, int identification, int[] scores){
        super(firstName, lastName, identification);
        this.testScores = scores;
    }

    public char calculate() {
        int average = 0;
        for(int i = 0; i < testScores.length; i++){
            average += testScores[i];
        }
        average = average / testScores.length;

        if(average >= 90) {
            return 'O'; // Outstanding
        }
        else if(average >= 80) {
            return 'E'; // Exceeds Expectations
        }
        else if(average >= 70) {
            return 'A'; // Acceptable
        }
        else if(average >= 55) {
            return 'P'; // Poor
        }
        else if(average >= 40) {
            return 'D'; // Dreadful
        }
        else {
            return 'T'; // Troll
        }
    }
}

Problem solution in c++ programming language.

class Student :  public Person{
    private:
        vector<int> testScores;  
    public:
        Student(string firstName, string lastName, int identification, vector<int> scores) : Person(firstName, lastName, identification) {
            this->testScores = scores;
        }   

        char calculate() {
            int average = 0;
            for(int i = 0; i < testScores.size(); i++) {
                average += testScores[i];
            }
            average = average / testScores.size();

            if(average >= 90) {
                return 'O'; // Outstanding
            }
            else if(average >= 80) {
                return 'E'; // Exceeds Expectations
            }
            else if(average >= 70) {
                return 'A'; // Acceptable
            }
            else if(average >= 55) {
                return 'P'; // Poor
            }
            else if(average >= 40) {
                return 'D'; // Dreadful
            }
            else {
                return 'T'; // Troll
            }
        }
};

Problem solution in C Sharp programming language.

class Student : Person{
    private int[] testScores;  
  
    /* 
    *   Class Constructor
    *   
    *   Parameters: 
    *   firstName - A string denoting the Person's first name.
    *   lastName - A string denoting the Person's last name.
    *   id - An integer denoting the Person's ID number.
    *   scores - An array of integers denoting the Person's test scores.
    */
    // Write your constructor here
    public Student(string firstName, string lastName, int id, int[] scores) : base (firstName, lastName, id)
    {
        testScores = scores;
    }
    /* 
    *   Method Name: Calculate
    *   Return: A character denoting the grade.
    */
    // Write your method here
    public char Calculate()
    {
        int score = testScores.Sum() / testScores.Length;
        
        if (score >= 90)
            return 'O';
        
        if (score >= 80)
            return 'E';
        
        if (score >= 70)
            return 'A';
        
        if (score >= 55)
            return 'P';
        
        if (score >= 40)
            return 'D';
        
        return 'T';
    }
}

Problem solution in JavaScript programming language.

class Student extends Person {
    
    constructor(firstName, lastName, identification, scores) {
        super(firstName, lastName, identification);
        this.testScores = scores;
    }
    
    calculate() {
        let average = this.testScores.reduce(
            function(a, b) {
                return a + b
            }, 
            0
        ) / this.testScores.length

        if (average >= 90) {
            return 'O'
        }
        else if(average >= 80) {
            return 'E'
        }
        else if(average >= 70) {
            return 'A'
        }
        else if(average >= 55) {
            return 'P'
        }
        else if(average >= 40) {
            return 'D'
        }
        else {
            return 'T'
        }
    }
}

Problem solution in Python programming language.

    def __init__(self, firstName, lastName, idNumber, scores):
        Person.__init__(self, firstName, lastName, idNumber)
        self.testScores = scores
  
    def calculate(self):
        average = 0
        for i in self.testScores:
            average += i

        average = average / len(self.testScores)
  
        if(average >= 90):
            return 'O' # Outstanding
        elif(average >= 80):
            return 'E' # Exceeds Expectations
        elif(average >= 70):
            return 'A' # Acceptable
        elif(average >= 55):
            return 'P' # Poor
        elif(average >= 40):
            return 'D' # Dreadful
        else:
            return 'T' # Troll

Problem solution in Ruby programming language.

class Student <Person
    def initialize(firstName, lastName, id, scores)
        super(firstName, lastName, id)
        @scores = scores
    end
    def calculate()
        sumScores = 0.to_i
        @scores.each do |x|
            sumScores = sumScores + Integer(x)
        end
        average = sumScores / @scores.count

        if(average >= 90)
            return 'O' # Outstanding
        elsif(average >= 80)
            return 'E' # Exceeds Expectations
        elsif(average >= 70)
            return 'A' # Acceptable
        elsif(average >= 55)
            return 'P' # Poor
        elsif(average >= 40)
            return 'D' # Dreadful
        else
            return 'T' # Troll
        end
    end
end

Problem solution in the Swift programming language.

// Class Student
class Student: Person {
 var testScores: [Int]
 
 // Write the Student class initializer
 init(firstName: String, lastName: String, identification: Int, scores: [Int]) {
  self.testScores = scores;
  super.init(firstName: firstName, lastName: lastName, identification: identification);
 }
 
 // Write the calculate method
 func calculate() -> String {
  var average = 0;
  for i in testScores {
   average += i;
  }
  average = average / testScores.count;

  if(average >= 90) {
   return "O"; // Outstanding
  }
  else if(average >= 80) {
   return "E"; // Exceeds Expectations
  }
  else if(average >= 70) {
   return "A"; // Acceptable
  }
  else if(average >= 55) {
   return "P"; // Poor
  }
  else if(average >= 40) {
   return "D"; // Dreadful
  }
  else {
   return "T"; // Troll
  }
 }
 
} // End of class Student