In this lab, you create a derived class from a base class, and then use the derived class in a Python program. The program should create two Motorcycle objects, and then set the Motorcycle’s speed, accelerate the Motorcycle object, and check its sidecar status.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Summary

In this lab, you create a derived class from a base class, and then use the derived class in a Python program. The program should create two Motorcycle objects, and then set the Motorcycle’s speed, accelerate the Motorcycle object, and check its sidecar status.

Instructions

  1. Open the file named Motorcycle.py.
  2. Create the Motorcycle class by deriving it from the Vehicle class. Call the parent class __init()__ method inside the Motorcycle class's __init()__ method.
  3. In theMotorcycle class, create an attribute named sidecar.
  4. Write a public set method to set the value for sidecar.
  5. Write a public get method to retrieve the value of sidecar.
  6. Write a public accelerate method. This method overrides the accelerate method inherited from the Vehicle class. Change the message in the accelerate method so the following is displayed when the Motorcycle tries to accelerate beyond its maximum speed: "This motorcycle cannot go that fast".
  7. Open the file named MyMotorcycleClassProgram.py.
  8. In the MyMotorcycleClassProgram, there are two Motorcycle objects named motorcycleOne and motorcycleTwo.
  9. Set the sidecar value of motorcycleOne to True and the sidecar value of motorcycleTwo to False.
  10. Set motorcycleOne’s maximum speed to 90 and motorcycleTwo’s maximum speed to 85.
  11. Set motorcycleOne’s current speed to 65 and motorcycleTwo’s current speed to 60.
  12. Accelerate motorcycleOne by 30 mph, and accelerate motorcycleTwo by 20 mph.
  13. Print the current speed of motorcycleOne and motorcycleTwo.
  14. Determine if motorcycleOne and motorcycleTwo have sidecars. If yes, display the following: "This motorcycle has a sidecar". If not, display the following: "This motorcycle does not have a sidecar".
  15. Execute the program.
1 # This program uses the programmer-defined Motorcycle class.
3 # Do NOT edit this file. Write your code in Motorcycle.py,
4 # then open this file and click "Run Code".
6 from Motorcycle import Motorcycle
B motorcycleOne = Motorcycle(90.0, 65.0, True)
e motorcycleTwo = Motorcycle(85.0, 60.0, False)
1 motorcycleOne.accelerate(30.0)
2 motorcycleTwo.accelerate(20.0)
4 print("The current speed of motorcycleOne is " + str(motorcycleOne.speed))
5 print("The current speed of motorcycleTwo is " + str(motorcycleTwo.speed))
7 if motorcycleOne.get_sidecar():
print ("This motorcycle has a sidecar")
e else:
print ("This motorcycle does not have a sidecar")
2 if motorcycleTwo.get_sidecar():
print("This motorcycle has a sidecar")
4 else:
print("This motorcycle does not have a sidecar")
Transcribed Image Text:1 # This program uses the programmer-defined Motorcycle class. 3 # Do NOT edit this file. Write your code in Motorcycle.py, 4 # then open this file and click "Run Code". 6 from Motorcycle import Motorcycle B motorcycleOne = Motorcycle(90.0, 65.0, True) e motorcycleTwo = Motorcycle(85.0, 60.0, False) 1 motorcycleOne.accelerate(30.0) 2 motorcycleTwo.accelerate(20.0) 4 print("The current speed of motorcycleOne is " + str(motorcycleOne.speed)) 5 print("The current speed of motorcycleTwo is " + str(motorcycleTwo.speed)) 7 if motorcycleOne.get_sidecar(): print ("This motorcycle has a sidecar") e else: print ("This motorcycle does not have a sidecar") 2 if motorcycleTwo.get_sidecar(): print("This motorcycle has a sidecar") 4 else: print("This motorcycle does not have a sidecar")
1 class Vehicle:
def -_init__(self):
2
3
self._fuel_capacity = 0
4
self._max_speed = 0
5
self._current_speed = 0
def set speed(self, speed):
8
self._current_speed = speed
9
def get_speed (self):
_1
2
3
_4
_5
_6
return self._current_speed
def accelerate(self, mph):
if self._current_speed + mph < max_speed:
self._current_speed = self._current_speed + mph
else:
.7
print("This vehicle cannot go that fast.")
8
_9
def set_fuel_capacity(self, fuel):
self._fuel_capacity = fuel
21
22
def get_fuel_capacity(self):
23
return self.-fuel_capacity
24
25
def set_max_speed (self, max):
26
self._max_speed = max
27
def get_max_speed(self):
return self. _max_speed
28
29
Transcribed Image Text:1 class Vehicle: def -_init__(self): 2 3 self._fuel_capacity = 0 4 self._max_speed = 0 5 self._current_speed = 0 def set speed(self, speed): 8 self._current_speed = speed 9 def get_speed (self): _1 2 3 _4 _5 _6 return self._current_speed def accelerate(self, mph): if self._current_speed + mph < max_speed: self._current_speed = self._current_speed + mph else: .7 print("This vehicle cannot go that fast.") 8 _9 def set_fuel_capacity(self, fuel): self._fuel_capacity = fuel 21 22 def get_fuel_capacity(self): 23 return self.-fuel_capacity 24 25 def set_max_speed (self, max): 26 self._max_speed = max 27 def get_max_speed(self): return self. _max_speed 28 29
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY