You have to implement a Sedan class, which inherits from the Car class and contains a SedanEngine object.
Note: In such a composition relation, the Sedan class will be responsible for SedanEngine lifetime.
Consider this diagram for reference:
Task 1
The Car initializer should take arguments in the order Car(model,color).
The Car class should have two properties:
model
color
The Car class should have one method:
printDetails(), which will print model and color of the Car object
Task 2
The SedanEngine class will have two methods:
start(), which will print:
Car has started.
stop(), which will print:
Car has stopped.
Task 3
The Sedan initializer should take arguments in the order Sedan(model, color).
The Sedan class will have one property:
engine, which is a SedanEngine class object that should be created when the object is initialized
The Sedan class will have two methods:
setStart(), which will call the start() method of SedanEngine.
setStop(), which will call the stop() method of SedanEngine.
Sample input
car1 = Sedan("Toyota","Grey")
car1.setStart()
car1.printDetails()
car1.setStop()
Sample output
After the implementation of your classes, the code below should produce the following output:
Car has started.
Model: Toyota
Color: Grey
Car has stopped.
Coding exercise
First, take a close look, and then, design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so initially, try to solve it on your own. If you get stuck, you can always refer to the solution provided in the next lesson.