Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.hackerrank.com/challenges/30-inheritance/
- 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){
- this.firstName = firstName;
- this.lastName = lastName;
- this.id = id;
- this.testScores = scores;
- }
- /*
- * Method Name: Calculate
- * Return: A character denoting the grade.
- */
- // Write your method here
- public char Calculate(){
- int sum = 0;
- int db = 0;
- foreach(int i in this.testScores){
- sum += i;
- db++;
- }
- int av = sum / db;
- if(av >= 90){
- return 'O';
- }
- else if(av >= 80){
- return 'E';
- }
- else if(av >= 70){
- return 'A';
- }
- else if(av >= 55){
- return 'P';
- }
- else if(av >= 40){
- return 'D';
- }
- else{
- return 'T';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement