Question: Chapter 4 4.1 a) Write a class Student that has the following attributes: -name: String, the student's name (Last, First format) - enrollment date (a

 Chapter 4 4.1 a) Write a class Student that has the

Chapter 4 4.1 a) Write a class Student that has the following attributes: -name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date: Student (String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables -- issued discussed in Chapter 3 (class Employee). Write contracts for all methods: preconditions/postconditions. Write the class invariant in the class javadoc comment. b) Implement a static method in class Student public static Comparator Student> getCompByName() that returns a new Comparator object for Student that compares 2 Students objects by the attribute name. Implement a static method in class Student: public static Comparator Student> getCompByDate() that returns a new comparator object for Student that compares 2 Students objects by their enrollment date. You must use anonymous classes that implement the Comparator interface. c) Write a public static main() method in class Student that: - creates an ArrayList object called students - adds 4 new Student objects to the students list, with some made up names and dates - sort the students list by name and display the sorted collection to System.out. use function getCompByName) - sort the students list by enrollment date and display the sorted collection to System.out. use function getCompByDate()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!