Starting from:

$20

Practice Car Solution

Create a Java project in eclipse, called "PracticeCar"
Create a class called "Simulator", with a main() method.
Create a "Car" class, with a run() method. The main() method of Simulator will create an instance of a car object, and call that object's run() method.
Now, you will create additional classes that represent the different components of a car - the engine, the fuel tank, the wheels, etc. These classes should have methods related to their behaviors, and properties representing their various states (an engine is running or not, tires have levels of wear, etc).

Every class representing a car part should inherit from a superclass called "CarPart." The CarPart class will have all of the states and behaviors that are shared by all types of car parts (like condition and the ability to print a diagnostic report).
Make sure that your Car class creates an instance of each CarPart subclass, as part of its constructor. Parts that a car has multiples of (like wheels) should be stored in a collection.
Make sure that the run() method of the Car class does something with each instance of a CarPart subclass.

More products