Question
1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name (Last, First format) - enrollment
1. Do the following
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
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
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
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