logo Use SA10RAM to get 10%* Discount.
Order Now logo

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

expert
Shankar GhoshalData mining
(5/5)

593 Answers

Hire Me
expert
Kim WooddOthers
(5/5)

771 Answers

Hire Me
expert
William LongMathematics
(5/5)

662 Answers

Hire Me
expert
Abhilekh Nath DasComputer science
(/5)

622 Answers

Hire Me
Python Programming

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

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. 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

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme

Get Free Quote!

408 Experts Online