Question: x 4 | Polymorphism You are working on a simulation software for a traffic control system. Different types of vehicles such as cars, buses, and

x4| Polymorphism
You are working on a simulation software for a traffic control system. Different types of vehicles such as cars, buses, and bicycles interact with the traffic signals in different ways. Implement polymorphism to handle the behavior of each type of vehicle when they encounter a traffic signal with the following specifications:
Create a base Vehicle class that initializes with a string input argument that sets its one member variable:
MEMBER VARIABLES
name
MEMBER FUNCTIONS
obey_traffic_signal
takes in a string variable signal
Create two classes that inherit from Vehicle
Bicycle
override obey_traffic_signal so that:
if signal is "green"
print "Bicycle moves forward."
if signal is "red"
print "Bicycle stops."
Car
override obey_traffic_signal so that:
if signal is "green"
print "Car moves forward."
if signal is "red"
print "Car stops."
Create a main function that uses the below CLAs to:
Create a vehicle-inherited object
Call the objects obey_traffic_signal function with the CLA provided signal
Arguments
python tcs.py {car OR bicycle} green

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!