Create the parent class Vehicle. Give it attributes make, model, and mileage. It should have an accessor method displayInfo(). It should also have a modifier method addMileage() which adds an integer to the mileage (ex: addMileage(50) will add 50 to the mileage attribute.)
Create the subclass Bus. Give it the extra attribute fare.
Add the method calculateFare() with the parameter trips. Then, it should print the attribute fare multiplied by trips. (ex: If self.fare = 2.50 and we call calculateFare(4), it should return 10.0).
Override the method displayInfo() to also display the bus fare.
Instantiate/make an object of the class Bus. Run addMileage(100), then calculateFare(5), and lastly, displayInfo().
Resourses:
Class slides: Intro to Python 2022 (17) - Google Slides
Class code: Class-17
Contact Info:
shravyassathish@gmail.com (mentor)
kingericwu@gmail.com (TA)
felixguo41@gmail.com (TA)
class Car(vehicle):
def __init__(self, make, model, mileage, fare):
self.make = make
self.model = model
self.mileage = mileage
self.fare = fare
#3
def calculateFare(self, trips):
print(f"{self.fare * trips}")
#4
def displayInfo(self):
print(f"The make is {self.make}, the model is {self.model}, the mileage is {self.mileage}, the price is ${self.fare}.")
#5
car = Car("Car", "5682", 4423J, 6.45)
car.addMileage(100)
car.calculateFare(5)
car.displayInfo()