Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with Intro to Computer Science 2 (Python) problem: Do not define any variables in the classes below (e.g. self.x for some variable name

Need help with Intro to Computer Science 2 (Python) problem:

image text in transcribed

image text in transcribed

Do not define any variables in the classes below (e.g. self.x for some variable name x) other than the ones specified in the assignment description. If you believe you can't write a solution without defining extra variables, please ask so that I can give you suggestions. You are absolutely encouraged to use as many local variables (e.g. x for some variable name x) as you desire 1. Using the time module (discussed during class or in Section 4.5 of the textbook implement a class Vehicle (that is a subclass of the object class) supporting five methods: nit 0 which takes a string representing a model as a parameter and an integer representing model year. If the string for the model is non-empty and the value given for the model year is present, the constructor uses those to initialize the model and model year of the Vehicle. The constructor can also take only one parameter or none. Given one parameter, it uses that as the name and uses 2016 as the model year. Given no parameters it uses "Beater" as the model of the Vehicle and 2000 as the model year. Make sure to set the defaults in the header for the function as demonstrated in class. b. age0 which returns the age of the Vehicle. It must use the function localtime0 from the time module to compute the age of the person. It should do this by subtracting the person's birth year from the current year, which again, is obtained from the localtime0 function. The age should not be stored in a variable in the object since the age can potentially change as time passes c. model 0 which returns the model of the vehicle d. repr 0 which returns the canonical representation of the vehicle e. str 0 which returns a nicely formatted version of the vehicle, an example of which can be seen below. Note that this method should NOT duplicate the work done in the age method. Instead it should call the age method The following shows how the Vehicle class and its methods could be used my Car Vehicle Focus myCar age my Car Vehicle (Focus 1) print (myCar) This Focus is 1 years old your Car Vehicle your car. age 17 your Car Vehicle (Beater 17) print (your Car) This Beater is 17 years old

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

Students also viewed these Databases questions

Question

8. Satyam Computer Services Limited

Answered: 1 week ago

Question

2. Explain how the role of training is changing.

Answered: 1 week ago

Question

7. General Mills

Answered: 1 week ago