Question: For this lab, you will be writing one abstract class and two subclasses, as directed below. For each class, open a new Java class file:

For this lab, you will be writing one abstract class and two subclasses, as directed below. For each class, open a new Java class file:
Write an abstract class named Vehicle that implements that Comparable interface. It should have two private instance variables: an int called year, and a String called make. There is one abstract void method called cargo. Vehicles are compared by their year, which means when sorted they will be in order by year. There is also a toString method which prints the year and make with labels, on separate lines (see Sample Output). Dont forget an appropriate constructor.
Write a subclass of Vehicle called Car. Car has one instance variable, a double named trunk which stores the trunk space square footage. Make sure you have an appropriate constructor. The cargo method for Car should print the trunk space with a label (see Sample Output).
Write a subclass of Vehicle called Truck. Truck has one instance variable, a String named bed which stores the capacity of the trucks bed (for example, 1/4 ton). Make sure you have an appropriate constructor. The cargo method for Truck should print the bed capacity with a label (see Sample Output).
In your main method, create an array of 2 Car and Truck objects, then use the available methods you have created to result in an output that matches the Sample Output. Add additional car and truck objects to the array and then call the Arrays.sort() method on your array. This tests to maek sure your comparable method works correctly. You can use different values if you like, but the format/labels should match.

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 Programming Questions!