I have this project I am working on which I have the base and derived classes st
ID: 3570616 • Letter: I
Question
I have this project I am working on which I have the base and derived classes started, but I am unsure how to proceed with the code to tie them together within the methods. Also, I am not certain how to build the collection class described in the last section. Here is the problem:
Develop a class hierarchy implementing polymorphism and utilize a standard collection algorithm to store and manipulate objects of the classes in the hierarchy.
Create a set of related classes.
Base Class: abstract Car implements Comparable
Instance Variables:
brand, year, powerSource, licensePlate
Constructors: standard constructors
Instance methods: Accessors, Mutators, toString(), equals(), abstract refillEnergy()
Derived Classes: GasolineCar
Adds an instance variable representing gas tank capacity and associated methods, implements the abstract method with a statement about refilling the gas tank, overrides the toString() method to call the toString() in the parent class and add specific information about this kind of car.
ElectricCar
Adds an instance variable representing the number of amps supplied by the battery, implements the abstract method with a statement about recharging the battery daily, overrides the toString() method to call the toString() in the parent class and add specific information about this kind of car.
HybridCar
Adds an instance variable representing gas tank capacity and associated methods, adds an instance variable representing the number of amps supplied by the battery, implements the abstract method with a statement about refilling the gas and a statement about recharging the battery daily, overrides the toString() method to call the toString() in the parent class and add specific information about this kind of car.
Create a class that creates a collection in which to store Cars:
This class will instantiate some cars of each kind and store them in the collection. The information about each of the cars will be displayed by accessing the car object from the collection.
The collection should then be sorted into ascending order according to the natural collating sequence developed for car objects in the Car class. The information about the cars should be displayed again to demonstrate that they are now in ascending order.
Use more car objects to search in the collection for a match. One car should be found in the collection; the other should not.
The application should display the results of both searches.
Explanation / Answer
contact on timacs12@gmail.com