Question
public class Student { private String sid; private int grade; public Student(String sid, int grade) { this.sid = sid; this.grade = grade; } /* *
public class Student { private String sid; private int grade; public Student(String sid, int grade) { this.sid = sid; this.grade = grade; } /* * Purpose: get this student's sid * Parameters: none * Returns: String - this student's sid */ public String getSid() { return sid; } /* * Purpose: update this student's grade * Parameters: int - the new grade * Returns: void - nothing */ public void setGrade(int newGrade) { grade = newGrade; }
/* * Purpose: get this student's grade * Parameters: none * Returns: int - this student's grade */ public int getGrade() { return grade; } /* * Purpose: get a string representation of this student * Parameters: none * Returns: String - the string representation */ public String toString() { return sid + ": " + grade; } /* * Purpose: determine if this student is equivalent * to the given other student * Parameters: Student other - the student to compare to * Returns: boolean - true if they are equal, false otherwise */ public boolean equals(Student other) { return this.sid.equals(other.getSid()); } /* * Purpose: determine whether this student has a higher * grade than the given other student * Parameters: Student other - the student to compare to * Returns: boolean - true if this student has a higher grade */ public boolean higherGradeThan(Student other) { return this.grade > other.getGrade(); } }
public class UvicCourse { private String name; private Student[] classList;
public UvicCourse(String name, Student[] classList) { // TODO: fix this this.name = name; this.classList = classList ; }
/* * Purpose: get this course's name * Parameters: none * Returns: String - this course's name */ public String getName() { return name; }
/* * Purpose: get this course's classlist * Parameters: none * Returns: Student[] - the array of students in this class */ public Student[] getClassList() { return classList; }
/* * Purpose: calculate the average grade of all students in this course * Parameters: none * Returns: double - the average grade of all students, * or 0.0 if there are no enrolled students */ public double averageGrade(Student[] classList) { double sum = 0; int count = 0; for(int i = 0; i < classList.length;i++){ sum =+ i.getGrade(); count++;
} double average = sum / count; return average; // so it compiles }
/* * Purpose: gets the grade of the student with given sid * Parameters: String sid - the sid of the student to search for * Returns: int - the grade of the students with given sid, * or -1 if no student with given sid is in * enrolled in this class */ public int getGrade(String sid) { int grade = -1; // TODO: implement this return grade; // so it compiles }
/* * Purpose: determines if s is in this course's class list * Parameters: Student s - the student * Returns: boolean - true if this course's class list contains s */ public boolean hasStudent(Student s) { boolean isFound = false; // TODO: implement this return isFound; // so it compiles }
/* * Purpose: updates the grade of the student with given studentSid to * newGrade if the student is found in this course's class list * Parameters: String studentSid - the sid of the student to update * int newGrade - the new grade for the student * Returns: void - nothing */ public void updateGrade(String studentSid, int newGrade) { // TODO: implement this }
/* * Purpose: add the given student to this course's classlist * Parameters: Strudent newStudent - student to add to class list * Returns: void - nothing * Precondition: newStudent is not already a student in classList */ public void addStudent(Student newStudent) { Student[] updatedList = new Student[classList.length+1]; // TODO: implement this classList = updatedList; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started