Having trouble with this Java Assignment. Not exactly sure where to start. Classes included with the problem: public class Main { public static void main(String[]
Having trouble with this Java Assignment. Not exactly sure where to start.
Classes included with the problem:
public class Main { public static void main(String[] args) { Student
Student
import java.util.ArrayList; import java.util.Collections;
public class Student
}
Thanks in advance for the assistance.
Head of the Class Purpose To review generics Directions For this lab you will need to download HeadOfTheClass.zip from Pilot. This code contains a Student class that uses generics to store an ArrayList of grades of type E, where is anything that implements the Comparable interface. There are methods to add a new grade and retrieve the student's grade on a particular assignment. The other class contains a main method that exercises the methods in the Student class for two different datatypes: int and double. Your tasks for this lab are: Add a method called getMedianGrade to the Student class that returns the middle of the student's grades when they are placed in ascending order. If the student has an even number of grades, return the higher of the two in the middle. Keep in mind that the method to get the student's grade on a particular assignment should still function correctly after the getMedianGrade method is called. Add the ability to sort students alphabetically based on name or based on their median grade. Note that only students with the same type of grades (e.g. integers or doubles) need to be sortable. In the main method or using JUnit tests, if you prefer) write additional code to test the getMedianGrade and different sort functionality. Hint1: The easiest way to get the median value from a list of values is to sort the list first and then get the item in the middle of the list. However, you don't want to sort the student's ArrayList of grades directly, because that will disturb the functionality of the getGradeOnAssignmentX method. Instead, you should copy the grades into a new ArrayList and sort the copy. Hint2: Because you need to sort the Student objects two different ways, you will need to both implement Comparable and write a Comparator class. Example This example assumes the following students received these grades: Alice: 90, 100, 85 Bob: 82.7, 64.2, 91.7, 70.4 Carol: 72, 57, 71 Aaron: 50,50,50 Note that we do not include Bob in testing the sort functionality, because his grades are of a different datatype (doubles versus integers). Alice's median grade is 90 Alice got a 100 on the second assignment. Bob's median grade is 82.7 Bob got a 82.7 on the first assignment. Ordered by name Aaron 50 Alice 90 Carol 71 Ordered by median grade Alice 90 Carol 71 Aaron 50
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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