Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions