Question: In this assignment, you will leverage inheritance and polymorphism to create more sophisticated, detailed functionality for the car classes developed so far. In particular you

In this assignment, you will leverage inheritance and polymorphism to create more sophisticated, detailed functionality for the car classes developed so far. In particular you will practice: definition and implementation of abstract methods; constructor overloading; implementation of interface contracts (in this case: to make vehicle objects comparable); use of inheritance and polymorphism; identifying common fields/methods across derived classes and moving them into an abstract base class to improve reuse. Below is a rough sketch of some of the classes and the hierarchy you'll be developing in this assignment: The classes Sedan and Truck point up to the abstract class Vehicle, and the arrows are labeled "is-a" to imply that they inherit from Vehicle. Vehicle points up to the Comparable interface to show that it implements Comparable. The classes Garage, AutoModel, and Manufacturer are shown to the left of this hierarchy with no arrows linked to them. Image Description While certain parts of the previous assignment can be reused (such as the (auto)model and manufacturer classes)-- you might prefer to start fresh. Getting Started: To get started, open IntelliJ and create a new java project named asg3(be sure to put it in your ist242/assignments directory). Part 1: Adding a Manufacturer and AutoModel Class Provide a Manufacturer class that stores the manufacturer's name and country. This class (along with all other classes specified in this assignment) should provide a suitable constructor, appropriate access modifiers, and getter methods. Additionally, override the toString() such that instances of the Manufacturer object are rendered as follows: ,(recall that anything in <..> is replaced by its corresponding field). Now add a class to represent an automobile's model (AutoModel). This class should be able to store the name of the model, whether or not it is still in production, and a list of Year objects denoting the years it was in production. In the constructor, include a defensive check that ensures the passed-in year list is nonempty (if it is, throw an IllegalArgumentException). Now override the toString() method to render AutoModel objects as follows: , in production =, Note: that you do not need to store trims anymore (or be able to add trims anymore). Part 2: Stubbing out a Vehicle Class Hierarchy Now create empty classes for a Sedan, Vehicle, and Truck. Note that you do NOT have to create the Comparable interface yourself -- it already exists in Java's libraries (you'll just be implementing a method the interface exports in Part 3). Here are some general notes to follow when writing these classes: the Sedan and Truck classes should extend the Vehicle class, the Vehicle class must include an abstract method, numberOfWheels, which takes nothing as a formal parameter and returns an int, a constructor in each subclass must invoke a super(..) constructor -- no empty/default constructors are needed in this assignment, The Sedan should be able to store: the manufacturer (use your Manufacturer class), the model (use your AutoModel class), the sedan's mpg. Implement the numOfWheels method -- it should always return 4. Provide a toString() that resembles the following: (), mpg: The Truck should be able to store: the manufacturer, whether or not the truck is dually, the model, mpg, Implement the numberOfWheels method such that it returns 6 if the truck is a dually and 4 if it isn't. Now provide an overloaded constructor that invokes the full constructor using the this(..) command. The shorter, overloaded constructor should assume that the Truck being constructed is not a dually. Override toString() to print the additional information as follows: (), mpg: , is-dually = More on The Vehicle Class: You will need to determine what should be stored in this class based on what you identify as the fields and methods common between both types of vehicles. Once you determine what to store in the vehicle base class, create a suitable constructor (and the subclasses should "super" up the required information). The vehicle class should provide getter methods for: each field that you determine should be stored in vehicle (based on observed duplication in the subclasses) a getter method to retrieve the release year of the vehicle (use Java's Year class as the return type) hint: the constructor for Vehicle should NOT take a parameter of type Year directly, rather, it should be obtained via the AutoModel class (this suggests at least one field that the Vehicle class should store) The class should contain the abstract method, numberOfWheels (specified above), and another method, howFarWith(int numOfGallons) that returns how many miles the car will g

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!