Question
User Defined Automobile Class Goals: Identify items in the Automobile class and first test file. Construct the variable trace table and predict the output of
User Defined Automobile Class
Goals:
Identify items in the Automobile class and first test file.
Construct the variable trace table and predict the output of the second test file.
Relevant Examples:
Pet, BankAccount, and Card Examples.
Details
Identify the following items in the Automobile class automobile.py and test file test1.py. Class Name Instance Variable Instance Method Public Member Private Member Dunder Method Constructor Local Variable Standalone Method Parameter Argument
Construct the variable trace table and predict the output from the test file test2.py. You can fill in this variable trace table:
Local Automobile object herbie Automobile object christine Variable ======================== =========================== i model color velocity model color velocity +------+ +-----+-----+---------+ +-----+-----+---------+ | | | | | | | | | | +------+ +-----+-----+---------+ +-----+-----+---------+ | | | | | | | | | | +------+ +-----+-----+---------+ +-----+-----+---------+ | | | | | | | | | | +------+ +-----+-----+---------+ +-----+-----+---------+ You may need more than 3 rows in your table
Also predict the output.
Automobile.py:
# automobile.py file class Automobile: def __init__(self, the_model, the_color): self.model = the_model self.color = the_color self.velocity = 0.0 def __str__(self): return f"Model: {self.color} -- Color: {self.color}" def accelerate(self): self.velocity += 15 if self.velocity > 120.0: self.velocity = 120.0 def brake(self): self.velocity -= 20 if self.velocity < 0.0: self.velocity = 0.0
test1.py:
# Automobile Example # test1.py file from automobile import Automobile auto = Automobile("Ford Taurus", "red") print(str(auto)) # Next line has same effect as preceding line. # str method is automatically called when # an object printed. print(auto) print(auto.model, auto.color) auto.accelerate( ) auto.accelerate( ) auto.accelerate( ) print(auto.velocity) auto.brake( ) auto.brake( ) print(auto.velocity) auto.brake( ) print(auto.velocity)
Test2.py:
from automobile import Automobile herbie = Automobile("VW Bug", "yellow") christine = Automobile("Plymouth Fury", "red") print(christine.color) herbie.color = "white" for i in range(0, 5): herbie.accelerate( ) christine.accelerate( ) print("herbie", herbie.velocity) print("christine", christine.velocity) for i in range(0, 3): herbie.brake( ) print(christine.velocity, herbie.velocity) print(herbie) print(christine)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started