Challenge 1: Cars and Engines!

Sumit Rawal answered on May 17, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Solution Review 1: Cars and Engines!
  • when did jeep start making cars

  • Challenge 1: Cars and Engines!

    0

    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. 

    Popularity 1/10 Helpfulness 1/10 Language python
    Source: Grepper
    Tags: python
    Link to this answer
    Share Copy Link
    Contributed on May 17 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.