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 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
