1. Engineering
  2. Computer Science
  3. instructions suppose we have a class student with these two...

Question: instructions suppose we have a class student with these two...

Question details

Instructions:

Suppose we have a class Student with these two public methods:

public String getName();

pulbic double getScore();

the static method we create is an array of Student objects, so an array not lists. The student class also has two public getter methods for getting the name and score. The static method we create has to return the name of the student in the Student array with the highest score.

Curious if I should have the return type stay as is, or if I should allow the String to include more names or should the return variable be an array?

And any other input on what you think would be beneficial, thanks.

public static String gethighest(String[ ] students) {

double highest_score = 0;

String highest_score_student = " ";

for(String s : students) {

if (s.getScore() > highest_score) {

highest_scoring_student = s.getName();

highest_score = s.getScore();

}

}
return highest_scoring_student;

}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution