We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
classStudentextendsPerson{privateint[]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. */// Write your constructor hereStudent(StringfirstName,StringlastName,intid,int[]scores){super(firstName,lastName,id);this.testScores=scores;}/* * Method Name: calculate * @return A character denoting the grade. */// Write your method herepubliccharcalculate(){intsum=0;for(inti=0;i<testScores.length;i++){sum+=testScores[i];}intavg=sum/testScores.length;if(90<=avg&&avg<=100){return'O';}elseif(80<=avg&&avg<90){return'E';}elseif(70<=avg&&avg<80){return'A';}elseif(55<=avg&&avg<70){return'P';}elseif(40<=avg&&avg<55){return'D';}else{return'T';}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Inheritance
You are viewing a single comment's thread. Return to all comments →
Here is my wokring solution in java-