Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using your Student class from Question 1, write an efficient method public Stude

ID: 663322 • Letter: U

Question

Using your Student class from Question 1, write an efficient method public Student topStudent(ArrayList cits 1001) that returns the Student object with the highest percentage score from a given ArrayList of Students called citslOOl. Write a suitable helper method that returns a student?s mark as a percentage rounded to the nearest integer. Javadoc comments are not required for this question. Write a Java class Student with three fields: name, mark and maxscore representing a student who has scored mark out of maxscore. The class has a constructor and two methods: addBonus adds a given bonus score to the student?s mark; toString returns a String summarising the current state of the Student. You should select suitable types and parameters for your class its constructor and methods. Javadoc comments are not required for this question.

Explanation / Answer

import java.io.*;
import java.util.*;

class Student{
String name;
float marks;
int maxscore;
public Student(String n,float m,int maximum){
name = n;
marks = m;
maxscore = maximum;
}
public void addBonus(float bonus){
marks += bonus;
}
@Override
public String toString(){
System.out.println("-------------------------------------- DETAIL OF STUDENT ------------------------------------");
System.out.println("Student Name :- "+name);
System.out.println("His Marks :- " + marks + " OUT OF " + maxscore);
return "";
}
}

class main{
public static int convert(float f){
return Math.round(f);
}
public static Student topStudent(ArrayList<Student> cits1001){
Student s = null;
int max = -1;
Iterator itr = cits1001.iterator();
while (itr.hasNext() == true){
Student st = (Student)itr.next();
int per = convert(st.marks);
if (per > max){
max = per;
s = st;
}
}
return s;
}
public static void main(String[] args){

}
}