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. */publicStudent(StringfirstName,StringlastName,intid,int[]scores){super(firstName,lastName,id);testScores=scores;}/* * Method Name: calculate * @return A character denoting the grade. */publiccharcalculate(){doubleaverage=0;for(intscore:testScores){average+=score;}average/=testScores.length;if(average>=90){return'O';}elseif(average>=80){return'E';}elseif(average>=70){return'A';}elseif(average>=55){return'P';}elseif(average>=40){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 →
Java solution - passes 100% of test cases
From my HackerRank solutions.