AP Computer Science --- Haas --- ArrayOfObjects
/**
* <<< CODE COMPLETE!!! >>>
*/
public class Student {
private String name;
private int average;
public Student(String n, int r) {
name = n;
average = r;
}
public String getName() { return name;}
public int getAverage() { return average; }
public String toString() {
return "Name: " + getName() +
" Average: " + getAverage();
}
}
/**
* <<< Code NOT complete >>>
*/
public class Tester
{
/*** <<< This method is NOT complete >>>
* returns the class average
***/
public static double classAverage(Student[] s)
{
// <<< COMPLETE THE CODE >>>
}
/*** <<< This method is NOT complete >>>
* returns the Valedictorian of the class
* (student with the highest average)
***/
public static Student getVal(Student[] s)
{
// <<< COMPLETE THE CODE >>>
}
public static void main(String[] args)
{
Student[] students = new Student[10];
students[0] = new Student("Jim",80);
students[1] = new Student("Sue",98);
students[2] = new Student("Bob",74);
students[3] = new Student("Liz",77);
students[4] = new Student("Lee",68);
students[5] = new Student("Tom",91);
students[6] = new Student("Kim",85);
students[7] = new Student("Lou",84);
students[8] = new Student("Jan",81);
students[9] = new Student("Ron",67);
System.out.println(getVal(students));
System.out.println("Class Average:" + classAverage(students));
}
}