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

707 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

707 Times Downloaded

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

expert
Um e HaniScience

771 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

832 Answers

Hire Me
expert
Husnain SaeedComputer science

964 Answers

Hire Me
expert
Atharva PatilComputer science

906 Answers

Hire Me