logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

Write python code for the below instructions (don’t forget to use the keyword “self” where appropriate in your code

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

1.  Write python code for the below instructions (don’t forget to use the keyword “self” where appropriate in your code):

    A. Define a Class called Car

    B. Inside your Car class, define a new member variable named condition and give it an initial value of "New".

    C. Define the constructor to take the following inputs: model, color, and MPG. Assign these inputs to member variables of the same name.

    D. Below your Car class, create a new object named my_car that is an instance of Car, passing the following as inputs to the new object: model = “Corvette”, color = “Black”,  and MPG = “30”.

    E. At the end of your code, use a print statement to display the model of my_car, the color of my_car, the MPG of my_car, and the condition of my_car.  Your output should duplicate what is shown below.


CODE

 

OUTPUT
Car Model: Corvette
Car Color: Black
Car Miles Per Gallon: 30
Car Condition: New

 

 

2.  Write python code for the below instructions (don’t forget to use the keyword “self” where appropriate in your code):

    A.  Define a Parent Class called Person

        a.  Inside your Person class, define new member variables called name, age, and gender.   Initialize these variables accordingly.

        b.  Define the constructor to take the following inputs: name, age, and gender.   Assign these inputs to member variables of the same name.


    B.  Define Child Class called Employee that inherits from the Person Class

        a.  Inside your Child class, define new member variables called title and salary.   Initialize these variables accordingly.

        b.  Define the constructor to take the following inputs: name, age, gender, title, and salary.   Assign these inputs to Class member variables of the same name.  Note, you will need to specifically call the Parent constructor method inside the Child constructor, passing the appropriate inputs to the Parent constructor.

    C.  Instantiate an Employee object called George with the following inputs: name = “George”, age = 30, gender = “Male”, title = “Manager”, and salary = 50000.


    D.  Print out the object’s name, age, gender, title, and salary to the console window.  Your output should duplicate what is shown below.

CODE

 

OUTPUT
George's info is:
Name: George
Age: 30
Gender: Male
Title: Manager
Salary: $50000

 

 

3.  Extending your answer from question #1, write the following python code to expand on the Car class.  Include the python code you developed when answering #1.

     A. Add class “getter” methods to return the values for model, color, and MPG

     B. Add class “setter” methods to change the existing values for model, color, and MPG.  The value to be used in the methods will be passed as an input argument.

     C. Add class method that will calculate and return the number of miles per tank of gas, where the method is provided the size of the gas tank as an integer input

     D. Below your Car class, create a new child class called mySportsCar that inherits from Car class.  Change the condition member variable to be "Used".  Make sure you call the Car class constructor with the appropriate inputs in the child class constructor.

     E. Instantiate an object of the mySportsCar class.  Use the following attributes when instantiating your object: model=Porsche, color=Red, MPG=15

     F. Print out the car and sports car object’s model, color, MPG, number of miles driven per tank of gas (car tank size = 20, sports car tank size = 15) to the console window.  Your output should duplicate what is shown below.


CODE

 

OUTPUT
My Car Info is
Car Model: Corvette
Car Color: Black
Car Miles Per Gallon: 30
Car Max Miles Per Tank: 600
Car Condition: New

My Sports Car Info is
Sports Car Model: Porsche
Sports Car Color: Red
Sports Car Miles Per Gallon: 15
Sports Car Max Miles Per Tank: 225
Sports Car Condition: Used

 

 

4. In Python a class can inherit from more than one class (Java does not allow this). The resulting class will have all the methods and attributes from the parent classes.  Do the following:

    • Create a class called Person.  In the class, define variables for storing name, date of birth, place of birth, and gender attributes.  In the class, define the constructor method, as well as methods for returning current values of the class attributes.

    • Create a class called Employee.  In the class, define variables for storing date of hire, department, and job title.  In the class, define the constructor method, as well as methods for returning current values of the class attributes.

    • Create a class called Salaried that inherits from both Person and Employee classes.  In the class define variables for storing the salary and tax bracket.  In the class, define the constructor method, as well as methods for returning current values of the class attributes.

    • Instantiate a Salaried object using the following attribute default values: Name: Lisa; Date of birth: January 1, 1980; Place of birth: New York, NY; Female, Date of hire: May 1, 2005, Department: Finance; Job Title: Manager; Salary: 100000; Tax Bracket: 29%.


CODE

 

OUTPUT
New Employee Info:
Name: Lisa
Date of Birth: January 1, 1980
Place of Birth: New York, NY
Gender: Female
Date of Hire: May 1, 2005
Department: Finance
Title: Manager
Salary: $100000
Tax Bracket: 29

(5/5)
Attachments:

Expert's Answer

909 Times Downloaded

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

909 Times Downloaded

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

550 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

962 Answers

Hire Me
expert
Husnain SaeedComputer science

966 Answers

Hire Me
expert
Atharva PatilComputer science

743 Answers

Hire Me
June
January
February
March
April
May
June
July
August
September
October
November
December
2025
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30