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.
--------
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:
Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def...
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, 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 (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...
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 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...
[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...
In Python Programming: Write a class named Car that has the following data attributes: _ _year_model (for the car’s year model) _ _make (for the make of the car) _ _speed (for the car’s current speed) The Car class should have an _ _init_ _ method that accepts the car’s year model and make as arguments. These values should be assigned to the object’s _ _year_model and _ _make data attributes. It should also assign 0 to the _ _speed...
Create a super class called Store which will have below member variables, constructor, and methods Member variables: - a final variable - SALES_TAX_RATE = 0.06 - String name; /** * Constructor:<BR> * Allows client to set beginning value for name * This constructor takes one parameter<BR> * Calls mutator method setName to set the name of the store * @param name the name of the store */ /** getName method * @return a String, the name of the store */...
public class Car { /* four private instance variables*/ private String make; private String model; private int mileage ; private int year; // /* four argument constructor for the instance variables.*/ public Car(String make) { super(); } public Car(String make, String model, int year, int mileage) { super(); this.make = make; this.model...
Lab 10C - Creating a new class This assignment assumes that you have read and understood the following documents: http://www.annedawson.net/Python3_Intro_OOP.pdf http://www.annedawson.net/Python3_Prog_OOP.pdf and that you're familiar with the following example programs: http://www.annedawson.net/python3programs.html 13-01.py, 13-02.py, 13-03.py, 13-04.py Instructions: Complete as much as you can in the time allowed. Write a Python class named "Car" that has the following data attributes (please create your own variable names for these attributes using the recommended naming conventions): - year (for the car's year of manufacture)...