Create a class named ElectricCar and display its model, color, mpg and condition. Note that ElectricCar is a class which inherits from its parent class named Car. In the parent class Car, it has a global variable named condition and its condition is set to ”new” at all time, and has three variables in the constructor ”model, color and mpg”. Furthermore, in the parent class Car, it contains two functions a display car function that displays the car attributes (such as model, color and mpg) and a drive car function that changes the condition to ”used”. Moreover, in the child ElectricCar class, it has one more attribute ”battery type” and it overrides the drive car function by setting the condition to ”like new”. To test your class CreateaElectricCarnamedmyCarbysettingmodel=”DeLorean”,color=”silver”, mpg=88, and battery type=”molten salt”. Display myCar’s condition by ”print(myCar.condition)”. Output is ”new”. Change myCar’s condition to ”like new” by myCar.drive car(). Again, display myCar’s condition by ”print(myCar.condition)”. Output is ”like new”. Display myCar’s information by ”myCar.display car()”. Output is ”This is a silver DeLorean with 88 MPG.”.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  1. Create a class named ElectricCar and display its model, color, mpg and condition. Note that ElectricCar is a class which inherits from its parent class named Car. In the parent class Car, it has a global variable named condition and its condition is set to ”new” at all time, and has three variables in the constructor ”model, color and mpg”. Furthermore, in the parent class Car, it contains two functions a display car function that displays the car attributes (such as model, color and mpg) and a drive car function that changes the condition to ”used”. Moreover, in the child ElectricCar class, it has one more attribute ”battery type” and it overrides the drive car function by setting the condition to ”like new”.

    To test your class

    • CreateaElectricCarnamedmyCarbysettingmodel=”DeLorean”,color=”silver”,

      mpg=88, and battery type=”molten salt”.

    • Display myCar’s condition by ”print(myCar.condition)”. Output is ”new”.

    • Change myCar’s condition to ”like new” by myCar.drive car(). Again, display myCar’s condition by ”print(myCar.condition)”. Output is ”like new”.

    • Display myCar’s information by ”myCar.display car()”. Output is ”This is a silver DeLorean with 88 MPG.”.

You may need the following hints to complete the question.
• Define a new class named Car. Inside your Car class, define a global variable
condition and give it an initial value of the string new.
• Define the -init-() function of the Car class to take four inputs: self, model,
color, and mpg. Assign the last three inputs to member variables of the same
name by using the self keyword.
Inside the Car class, add a method named display_car to Car that will reference
the Car's member variables to return the string, "This is a [color] [model] with
[mpg] MPG." You can use the str() function to turn your mpg into a string when
creating the display string.
• Inside the Car class, add a method drive_car that sets self.condition to the string
"used".
• Create a class ElectricCar that inherits from Car. Give your new class an init.()
method of that includes a battery_type member variable in addition to the model,
color and mpg.
• Inside ElectricCar add a new method drive_car that changes the car's condition
to the string "like new".
Transcribed Image Text:You may need the following hints to complete the question. • Define a new class named Car. Inside your Car class, define a global variable condition and give it an initial value of the string new. • Define the -init-() function of the Car class to take four inputs: self, model, color, and mpg. Assign the last three inputs to member variables of the same name by using the self keyword. Inside the Car class, add a method named display_car to Car that will reference the Car's member variables to return the string, "This is a [color] [model] with [mpg] MPG." You can use the str() function to turn your mpg into a string when creating the display string. • Inside the Car class, add a method drive_car that sets self.condition to the string "used". • Create a class ElectricCar that inherits from Car. Give your new class an init.() method of that includes a battery_type member variable in addition to the model, color and mpg. • Inside ElectricCar add a new method drive_car that changes the car's condition to the string "like new".
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education