Question

1) Using the Object-Oriented Programming Paradigm,implement the necessary code in Python creating a ‘Car’ class with...

1) Using the Object-Oriented Programming Paradigm,implement the necessary code in Python creating a ‘Car’ class with a constructor that stores all the Car information (ID, MAKE, MODEL, YEAR , COLOR, MILEAGE, PRICE_TO_DEALER, SALE_PRICE, PROFIT) as attributes.

2) Implement and add the following methods to the ‘Car' class in Question 1.

a) necessary getter methods

b) necessary setter methods

c) method to display all the information to the screen

d) a method to calculate the profit

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The python code to implement car class is below

# creating class named car
class car:
  
PROFIT=0 # initilizing the profit
  
# using constructure to initilize the car object   
def __init__(self,ID, MAKE, MODEL, YEAR , COLOR, MILEAGE, PRICE_TO_DEALER, SALE_PRICE):
self.ID=ID
self.MAKE=MAKE
self.MODEL=MODEL
self.YEAR=YEAR
self.COLOR=COLOR
self.MILEAGE=MILEAGE
self.PRICE_TO_DEALER=PRICE_TO_DEALER
self.SALE_PRICE=SALE_PRICE
  
# declaring the necessary getters and setters method
  
# getter and setter of make
def set_make(self, MAKE):
self.MAKE = MAKE
  
def get_make(self):   
return self.Make
  
# getter and setter of model
def set_model(self, MODEL):
self.MODEL = MODEL
  
def get_model(self):   
return self.MODEL
  
# getter and setter of MILEAGE
def set_mileage(self, MILEAGE):
self.MILEAGE = MILEAGE
  
def get_mileage(self):   
return self.MILEAGE
  
# getter and setter of PRICE_TO_DEALER   
def set_pricetodealer(self, PRICE_TO_DEALER):
self.PRICE_TO_DEALER = PRICE_TO_DEALER
  
def get_pricetodealer(self):   
return self.PRICE_TO_DEALER
  
# getter and setter of SALE_PRICE
def set_saleprice(self,SALE_PRICE):
self.SALE_PRICE=SALE_PRICE
  
def get_saleprice(self):
return self.SALE_PRICE
  
# function to calculate the PROFIT
def calculate_profit(self,SALE_PRICE,PRICE_TO_DEALER):
self.PROFIT=(SALE_PRICE-PRICE_TO_DEALER)
  
# function to return the calculate_profit   
def get_profit(self):
self.calculate_profit(self.SALE_PRICE,self.PRICE_TO_DEALER)
return self.PROFIT
  
# function to display the car information
def display_car_info(self):
print('The ID of the car is: ',self.ID)
print('The Make of the car is: ',self.MAKE)
print('The MODEL of the car is: ',self.MODEL)
print('The YEAR of the car is: ',self.YEAR)
print('The COLOR of the car is: ',self.COLOR)
print('The MILEAGE of the car is: ',self.MILEAGE)
print('The PRICE_TO_DEALER of the car is: ',self.PRICE_TO_DEALER)
print('The SALE_PRICE of the car is: ',self.SALE_PRICE)
self.calculate_profit(self.SALE_PRICE,self.PRICE_TO_DEALER)
print('The PROFIT of the car is: ',self.PROFIT)
  
  
new_car=car(12,'skoda','superb',2005,'white',15,3000,3500)
print("Displaying CAR information after object initilization:\n ")
new_car.display_car_info()

print("\nChanging the MAKE to AUDI, SALE_PRICE to 10000 and PRICE_TO_DEALER to to 8000 :\n")

new_car.set_saleprice(10000)
new_car.set_pricetodealer(8000)
new_car.set_make('Audi')
new_car.display_car_info()
  

CODE SCREENSHOT

main.py 1 # creating class named car 2. class car: PROFIT=@ # initilizing the profit # using constructure to initilize the ca32 33 34 # getter and setter of MILEAGE def set_mileage(self, MILEAGE) : self.MILEAGE = MILEAGE 36 def get_mileage(self): ret58 # function to return the calculate_profit def get_profit(self): self.calculate profit self. SALE_PRICE, self. PRICE_TO_DEA

OUTPUT SCREEN

input Displaying CAR information after object initilization: The ID of the car is: 12 The Make of the car is: skoda The MODEL

Add a comment
Know the answer?
Add Answer to:
1) Using the Object-Oriented Programming Paradigm,implement the necessary code in Python creating a ‘Car’ class with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I Need Help with this using Java Programming : Class name fname lname Class variable total...

    I Need Help with this using Java Programming : Class name fname lname Class variable total Number Constructor (no arguments) Constructor (takes two arguments, fname and lname) One getter method to return the fname and lname One setter method for fname and lname Inside Main: Create three objects with the following names Jill Doe John James Jack Smith When creating the first object (Should not be an anonymous object) use the argument-less constructor Then use the setter method to assign...

  • 1. Extending the answer from Python HW #7 for question #1, write the following python code...

    1. Extending the answer from Python HW #7 for question #1, write the following python code to expand on the Car class. Include the python code you developed when answering HW #7. Add class “getter” methods to return the values for model, color, and MPG 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. Add class method that will calculate...

  • BMI Class. Using JAVA write Object Oriented Programming by creating class, object and method , that...

    BMI Class. Using JAVA write Object Oriented Programming by creating class, object and method , that takes users' input (weight and Height) and calculates the BMI. If the result is less than 18.5 display "you are underweight", if the result is greater than 18.5 display "you have a normal weight", if the result is greater than 24.9 display "your weight is considered overweight", and the result is greater than 30 display "your weight is considered as obese" (BMI = 703...

  • *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented...

    *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented programming using classes to create objects. PROBLEM DEFINITION: Write a class named Employee that holds the following data about an employee in attributes: name, IDnumber, department, jobTitle The class should have 8 methods as follows:  For each attribute, there should be a method that takes a parameter to be assigned to the attribute. This is known as a mutator method.  For each...

  • SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The...

    SOLVE IN PYTHON: Exercise #1: Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: A private variable of type double named radius to represent the radius. Set to 1. Constructor Methods: Python : An overloaded constructor method to create a default circle. C# & Java: Default Constructor with no arguments. C# & Java: Constructor method that creates a circle with user-specified radius. Method getRadius() that returns the radius. Method setRadius()...

  • 1) Using the O-O Paradigm create a class in C++ for the object Dog 2) Implement...

    1) Using the O-O Paradigm create a class in C++ for the object Dog 2) Implement ALL the behaviors  (member functions/methods- including any needed constructors, and helper methods ) of the class. 3) Write the necessary Client/Application/User program The Client program should do the following: a) create at least 4 objects. b) show all the behaviors

  • In Python Programming: Write a class named Car that has the following data attributes: _ _year_model...

    In Python Programming: Write a class named Car that has the following data attributes: _ _year_model (for the car’s year model) _ _make (for the make of the car) _ _speed (for the car’s current speed) The Car class should have an _ _init_ _ method that accepts the car’s year model and make as arguments. These values should be assigned to the object’s _ _year_model and _ _make data attributes. It should also assign 0 to the _ _speed...

  • I need help with these Java programming assignements. public class Die { //here you declare your...

    I need help with these Java programming assignements. public class Die { //here you declare your attributes private int faceValue; //operations //constructor - public Die() { //body of constructor faceValue=(int)(Math.random()*6)+1;//instead of 1, use random approach to generate it } //roll operation public void roll() { faceValue=(int)(Math.random()*6)+1; }    //add a getter method public int getFaceValue() { return faceValue; }    //add a setter method public void setFaceValue(int value) { faceValue=value; } //add a toString() method public String toString() { String...

  • Write a python program using Object Oriented and do the following: 1. create class "cat" with...

    Write a python program using Object Oriented and do the following: 1. create class "cat" with the following properties: name, age (create constructor method: def __init__) 2. create class "adopter" with the following properties: name, phone 3. create class "transaction" with these properties: adopter, cat (above objects) cat1 = "puffy, 2" adopter1 = "Joe, 123" Test your program: Joe adopts puffy. Print: "Per Transaction 1 <joe> has adopted <puffy>" this can only be done with object oriented programming, no way...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT