Advertisement
minnera

#30daysofcode #day12

Oct 12th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. //https://www.hackerrank.com/challenges/30-inheritance/
  2.  
  3. class Student : Person{
  4.     private int[] testScores;  
  5.  
  6.     /* 
  7.     *   Class Constructor
  8.     *  
  9.     *   Parameters:
  10.     *   firstName - A string denoting the Person's first name.
  11.     *   lastName - A string denoting the Person's last name.
  12.     *   id - An integer denoting the Person's ID number.
  13.     *   scores - An array of integers denoting the Person's test scores.
  14.     */
  15.     // Write your constructor here
  16.     public Student(string firstName, string lastName, int id, int[] scores){
  17.         this.firstName = firstName;
  18.         this.lastName = lastName;
  19.         this.id = id;
  20.         this.testScores = scores;
  21.     }
  22.     /* 
  23.     *   Method Name: Calculate
  24.     *   Return: A character denoting the grade.
  25.     */
  26.     // Write your method here
  27.     public char Calculate(){
  28.       int sum = 0;
  29.       int db = 0;
  30.         foreach(int i in this.testScores){
  31.             sum += i;
  32.             db++;
  33.         }
  34.       int av = sum / db;
  35.       if(av >= 90){
  36.         return 'O';
  37.       }
  38.       else if(av >= 80){
  39.         return 'E';
  40.       }
  41.       else if(av >= 70){
  42.         return 'A';
  43.       }
  44.       else if(av >= 55){
  45.         return 'P';
  46.       }
  47.       else if(av >= 40){
  48.         return 'D';
  49.       }
  50.       else{
  51.         return 'T';
  52.       }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement