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
x 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
obeytrafficsignal
takes in a string variable signal
Create two classes that inherit from Vehicle
Bicycle
override obeytrafficsignal so that:
if signal is "green"
print "Bicycle moves forward."
if signal is "red"
print "Bicycle stops."
Car
override obeytrafficsignal 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 vehicleinherited object
Call the objects obeytrafficsignal function with the CLA provided signal
Arguments
python tcspy car OR bicycle green
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
