Question: 4.1 a. Write a class Car that has the following attributes: - make: String, the car make (e.g. Oldsmobile) model: String, the model name (e.g.

 4.1 a. Write a class Car that has the following attributes:

4.1 a. Write a class Car that has the following attributes: - make: String, the car make (e.g. Oldsmobile) model: String, the model name (e.g. "442") - built date: java.util.Date, the official manufacture date The Car class provides a constructor Car(String make, String model, Date whenBuilt) that initializes the corresponding fields. The Car class should have accessors for make, model, and the built date and a useful implementation of the toString() method Make sure the class is immutable. Be *careful* with that Date field -- remember what to do when sharing mutable instance variables -- issues discussed in Chapter 3 for a class called Employee. Write contracts for all methods: preconditions/postconditions Write the class invariant in the class javadoc comment. Some preconditions are trivial. Just say 'none b. Implement a static method in class Student public static Comparator object called cars - adds 4 new Car objects to the cars list, using real cars make/models. You can use bogus built dates. - sorts the cars list by make/model and displays the sorted collection to System.out. Uses function getCompByMakeModel() - sorts the cars list by built date and display the sorted collection to System.out. Uses 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!