Question

Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def...

Python 3>

Make a class called BMW:

Parameterized constructor with three instance variables (attributes):

Hint: def __init__(self, make, model, year)

Methods in BMW parent class (can leave as method stubs for now):

startEngine()

-must print "The engine is now on."

stopEngine()

-must print "The engine is now off."

Make another class called ThreeSeries

-Must inherit BMW

Hint: class ThreeSeries(BMW):

-Also passes the three attributes of the parent class and invoke parent

Hint: BMW.__init__(self, cruiseControlEnabled, make, model, year)

-Constructor must have the additional variable (attribute): cruiseControlEnabled (boolean)

Methods in ThreeSeries class (can leave as method stubs for now):

display()

-Must print the state of the cruiseControlEnabled attribute.

startEngine()

-Use super to use the functionality of parent method.

Hint: super().startEngine()

-And must additionally print "Button start is on."

NOTE: This will be an example of using super and method overriding if implemented correctly.

Similarly, make class called FiveSeries:

-Must inherit BMW

Hint: class FiveSeries(BMW):

-Also passes the three attributes of the parent class and invoke parent using the super() function.

Hint: super().__init__(parkingAssistEnabled, make, model, year)

-NOTE: you don't have to pass “self”.

-Constructor must have the additional variable (attribute): parkingAssistEnabled (boolean)

Methods in FIveSeries class (can leave as method stubs for now):

display()

-Must print the state of the parkingAssistEnabled attribute.


In the main section of your code:

Prompt the user for:

-Make

-Model

-Year

Ex.

Enter the threeseries make:

BMW

Enter model:

328i

Enter Year:

2018

Is cruise control on? (y or n)

y

Enter the fiveseries make:

BMW

Enter model:

328i

Enter Year:

2017

Is the parking assist enabled? (y or n)

n

-Create an object of the ThreeSeries class and of the FiveSeries class and invoke the constructor with the user input and the print the details using the methods in the classes.

Final Output Example:

Three Series...

This “Make” is a “Model” of “YEAR”

The engine is now on.

Button start is on.

Cruise control is on.

--------

FiveSeries...

This “Make” is a “Model” of “YEAR”

Starting engine...

The engine is now on.

Parking assist is off.

--------



0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python Code:

class BMW:
   def __init__(self, make, model, year):
       """ Constructor """
       self.make = make
       self.model = model
       self.year = year
      
   def startEngine(self):
       print("The engine is now on.")
      
   def stopEngine(self):
       print("The engine is now off.")
      
class ThreeSeries(BMW):
   def __init__(self, cruiseControlEnabled, make, model, year):
       """ Constructor """
       BMW.__init__(self, make, model, year)
       self.cruiseControlEnabled = cruiseControlEnabled
      
   def display(self):
       if self.cruiseControlEnabled.lower() == 'y':
           print("Cruise control is on.")
       else:
           print("Cruise control is off.")
      
   def startEngine(self):
       super().startEngine()
       print("Button start is on.")
  
  
class FiveSeries(BMW):
   def __init__(self, parkingAssistEnabled, make, model, year):
       """ Constructor """
       BMW.__init__(self, make, model, year)
       self.parkingAssistEnabled = parkingAssistEnabled
      
   def display(self):
       if self.parkingAssistEnabled.lower() == 'y' :
           print("Parking assist is on.")
       else:  
           print("Parking assist is off.")
      
  
def main():
   """ Main function """
   # Reading input from user
   print("Enter the three series make:")
   make = input()
   print("Enter model:")
   model = input()
   print("Enter year:")
   year = input()
   print("Is cruise control on? (y or n)")
   cruise = input()
  
   # Reading input from user
   print("Enter the five series make:")
   make5 = input()
   print("Enter model:")
   model5 = input()
   print("Enter year:")
   year5 = input()
   print("Is the parking assist enabled? (y or n)")
   parking = input()
  
   print("\n----------------------------------------\n")
  
   # Creating objects
   threeObj = ThreeSeries(cruise, make, model, year)
   print("Three Series...")
   print("This " + make + " is a " + model + " of " + year)
   threeObj.startEngine()
   threeObj.display()
  
   print("\n----------------------------------------\n")
  
   # Creating objects
   fiveObj = FiveSeries(cruise, make, model, year)
   print("Five Series...")
   print("This " + make + " is a " + model + " of " + year)
   fiveObj.startEngine()
   fiveObj.display()
  
  
# Calling main function
main()

___________________________________________________________________________________________________

Sample Run:

Add a comment
Know the answer?
Add Answer to:
Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON 3.6 Overview In this assignment we implement a class called TripleString. It consists of a...

    PYTHON 3.6 Overview In this assignment we implement a class called TripleString. It consists of a few instance attribute and a few instance methods to support those attributes. In the next assignment, the TripleString class will help us create a more involved application. Before we do that though, we have to thoroughly test our TripleString implementation. Specifications The class TripleString will contain symbolic constants, instance attributes, and instance methods. ▶ Class symbolic constants This class has 3 symbolic constants, which...

  • python code? 1. Create a class called Person that has 4 attributes, the name, the age,...

    python code? 1. Create a class called Person that has 4 attributes, the name, the age, the weight and the height [5 points] 2. Write 3 methods for this class with the following specifications. a. A constructor for the class which initializes the attributes [2.5 points] b. Displays information about the Person (attributes) [2.5 points] c. Takes a parameter Xage and returns true if the age of the person is older than Xage, false otherwise [5 points] 3. Create another...

  • Create a Python file (book.py) that has a class named Book. Book class has four attributes,...

    Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...

  • Create a Python file (book.py) that has a class named Book. Book class has four attributes, title...

    Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...

  • A) Please implement a Python script to define a student class with the following attributes (instance...

    A) Please implement a Python script to define a student class with the following attributes (instance attributes): cwid: student’s CWID first_name : student’s first name last_name: student’s last name gender: student’s gender gpa: student’s gpa Please make these attributes as private ones so they have to be accessed via getter/setter methods or property. For this purpose, please define a getter/setter method and property for each of the attributes. Another thing you need to do is to define a constructor that...

  • 1. Assume you have a Car class that declares two private instance variables, make and model....

    1. Assume you have a Car class that declares two private instance variables, make and model. Write Java code that implements a two-parameter constructor that instantiates a Car object and initializes both of its instance variables. 2. Logically, the make and model attributes of each Car object should not change in the life of that object. a. Write Java code that declares constant make and model attributes that cannot be changed after they are initialized by a constructor. Configure your...

  • Create an Item class, which is the abstract super class of all Items.           Item class...

    Create an Item class, which is the abstract super class of all Items.           Item class includes an attribute, description of type String for every item. [for eg. Book]                                                             A constructor to initialize its data member of Item class.               Override toString() method to return details about the Item class. Create the ExtraCharge interface with the following details.                       Declare a constant RATE with value 0.25   Declare a method called calculateExtraCharge(), which returns a double value. Create the...

  • STORAGE WARS - Create a class with the name and variables/attributes listed below. Create a default...

    STORAGE WARS - Create a class with the name and variables/attributes listed below. Create a default Constructor with no parameters that assigns default values for each variable. Then, create an overloaded Constructor (with one parameter for each variable). Finally, create a method that returns the total number of items in the storage container. NOTE: this method must not print anything. (50 points) Make sure to clearly label the variables/attributes, Constructors and Methods and to indicate which language you are answering...

  • This assignment involves writing a program that uses an abstract class and concrete subclasses. An abstract...

    This assignment involves writing a program that uses an abstract class and concrete subclasses. An abstract Vehicle class declares an abstract method named display() that is used to display vehicles. Vehicle has two subclasses: Boat and Car. A Boat has a length attribute, and a draft attribute (a draft is how far below the surface the bottom of the boat is). A Car has a make attribute and a year attribute. Appropriate getter, setter, and constructor methods should be defined...

  • [python3] Start by using UML and planning the functionality of each method (including the constructor, that...

    [python3] Start by using UML and planning the functionality of each method (including the constructor, that is, the __init__() method) Initialization of your objects must require at least one parameter (in addition to self) All of your objects attributes/fields should be 'private' and you should include getters and setters for each attribute/field You must be able to print your object in a meaningful way and you should define what it means for two objects to be equal Additionally, your object...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT