Program
import sys
""" A class that can be used to represent a car"""
class Car:
"""A simple attempt to represent a car."""
def __init__(self, make, model, year):
"""Initialize attributes for a car."""
self.make = make
self.model = model
self.year = year
def __str__(self):
return self.make + " " + self.model + " " +
str(self.year)
def __repr__(self):
return "\nMake: " + self.make + "\nModel: " + self.model + "\nYear:
" + str(self.year)
class GasCar(Car):
""" A car thats runs on gas """
def __init__(self, make, model, year,
gas_per_mile):
super().__init__(make, model, year)
self.gas_per_mile = gas_per_mile
def __str__(self):
return super().__str__() + " " + str(self.gas_per_mile) +
"\n"
def __repr__(self):
return super().__repr__() + "\nGas per mile: " +
str(self.gas_per_mile)
class ElectricCar(Car):
""" A car that runs on electric power """
def __init__(self, make, model, year,
battery_per_mile):
super().__init__(make, model, year)
self.battery_per_mile = battery_per_mile
def __str__(self):
return super().__str__() + " " + str(self.battery_per_mile) +
"\n"
def __repr__(self):
return super().__repr__() + "\nBattery per mile: " +
str(self.battery_per_mile)
def read_electric_cars():
""" function to read electric car from the file electric.txt
"""
with open("electric.txt") as file:
for line in file.readlines():
car_make, car_model, car_year, car_battery_per_mile =
line.strip(
'\n').split()
cars.append(ElectricCar(
car_make, car_model, car_year, car_battery_per_mile))
def read_gas_cars():
""" method to read gas car from the file gas.txt """
with open("gas.txt") as file:
for line in file.readlines():
car_make, car_model, car_year, car_gas_per_mile = line.strip(
'\n').split()
cars.append(GasCar(car_make, car_model,
car_year, car_gas_per_mile))
def write_electric_cars():
with open("electric.txt", 'w') as file:
for car in cars:
if isinstance(car, ElectricCar):
file.write(car.__str__())
def write_gas_car(gas_car):
with open("gas.txt", 'a') as file:
for car in cars:
if isinstance(car, gas_car):
file.write(car.__str__())
# car sell manger application
cars = []
def add_car():
""" function to add a new car """
try:
print("\nSelect the type of car\n1. Gas-powered\n2.
Electric-powered\n")
car_type = int(
input("Enter your choice: "))
if(car_type == 1):
# read data from the user
car_make = str(input("\nEnter the make of the car: "))
car_model = str(input("Enter the model of the car: "))
car_year = int(input("Enter the year of the car: "))
car_gas_per_mile = int(input("Enter the gas consumed for mile:
"))
# create car object and append to cars list
gas_car = GasCar(car_make, car_model, car_year,
car_gas_per_mile)
cars.append(gas_car)
elif(car_type == 2):
# read data from the user
car_make = str(input("\nEnter the make of the car: "))
car_model = str(input("Enter the model of the car: "))
car_year = int(input("Enter the year of the car: "))
car_battery_per_mile = int(
input("Enter the battery consumed for mile: "))
# create car object and append to cars list
electric_car = ElectricCar(
car_make, car_model, car_year, car_battery_per_mile)
cars.append(electric_car)
else:
print("Invalid entry")
# exception handling
except ValueError:
print("Value should be an integer")
except:
print("Something went wrong")
def delete_car():
""" function to delete an existing car """
for index in range(len(cars)):
print("Index:", index)
print(cars[index])
try:
index_to_delete = int(input("Enter the index of the car to delete:
"))
cars.remove(index_to_delete)
except ValueError:
print("Invalid Index value")
except:
print("Something went wrong")
def view_car():
""" function to display all cars in the user's car book """
print("Cars in the user's car book")
for car in cars:
print(car)
def car_manager_application():
try:
# read the cars in the file
read_electric_cars()
read_gas_cars()
print("*** Car Manager Application ***")
while(True):
# print menu
print("\nSelect an option from the menu")
print("1. Add car")
print("2. View car")
print("3. Delete car")
print("4. Exit program")
choice = int(input("Enter your choice: "))
if(choice == 1):
add_car()
elif(choice == 2):
view_car()
elif(choice == 3):
delete_car()
elif(choice == 4):
# write the cars to the respective files
write_electric_cars()
write_gas_car()
sys.exit(1)
else:
print("Please enter a valid choice")
except ValueError:
print("Value should be an integer")
except:
print("Something went wrong")
if __name__ == "__main__":
car_manager_application()



OUTPUT
*** Car Manager Application ***
Select an option from the menu
1. Add car
2. View car
3. Delete car
4. Exit program
Enter your choice: 1
Select the type of car
1. Gas-powered
2. Electric-powered
Enter your choice: 1
Enter the make of the car: Audi
Enter the model of the car: R8
Enter the year of the car: 2019
Enter the gas consumed for mile: 1
Select an option from the menu
1. Add car
2. View car
3. Delete car
4. Exit program
Enter your choice: 1
Select the type of car
1. Gas-powered
2. Electric-powered
Enter your choice: 2
Enter the make of the car: Tesla
Enter the model of the car: Roadster
Enter the year of the car: 2019
Enter the battery consumed for mile: 2

Hope this helps!
Please let me know if any changes needed.
Thank you!
I hope you're safe during the pandemic.
Create a python program based on the following requirements the program should also have to have...
language:python
VELYIEW Design a program that you can use to keep information on your family or friends. You may view the video demonstration of the program located in this module to see how the program should function. Instructions Your program should have the following classes: Base Class - Contact (First Name, Last Name, and Phone Number) Sub Class - Family (First Name, Last Name, Phone Number, and Relationship le. cousin, uncle, aunt, etc.) Sub Class - Friends (First Name, Last...
Note: You must write this program in Python. General Requirements The program should display a menu and allow the user to perform one of the following tasks. Add an item to the list Delete an item from the list Print the list Print the list in reverse Quit the program The program should run until the user chooses to quit. In Python, programmatically quitting the application is achieved with the exit() procedure. You should use a List to store the...
Write a java application that should have a menu system along the following lines (you can have sub-menus if you deem that to be necessary) 1) Ask the user how many books their application should store • The application then creates a suitable storage component for the books (i.e. an array of Book objects) 2) Add book details • You as the reader can add details of a book here (i.e. a Book object’s properties are given values). 3) Display...
Java Create a program for a car dealer to use where you have a class for Salesman, Cars, and the Records of sale. 4 salesman and 4 cars to start with but have array size for 50 cars, have space for 100 records in array. The program should have 6 options in the menu. buy car, sell car, show inventory, show salesman, show sales records, and exit. Salesman class - Name, ID number, Commision rate, Total commisions earned, Totals number...
Assignment Requirements
I have also attached a Class Diagram that describes the
hierarchy of the inheritance and interface behaviors . The link to
the PDF of the diagram is below
MotorVehical.pdf
Minimize File Preview
User Define Object Assignment:
Create a Intellij Project. The
Intellij project will contain three user defined
classes. The project will test two of the User Define Classes by
using the invoking each of their methods and printing the
results.
You are required to create three UML...
For Java Program In this lab you will gain experience using all the concepts we learned to this point, which include classes, methods, collections, and file input/output. Also, you will gain experience in team programming. This assignment will be completed by teams of 2. Each member must complete an equal amount of the work in order to receive credit for this assignment. You must write the programmer’s name in a comment for each method you write. You need to create...
python code
DC Final Project Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. The following two lines are written in a File called FuelEffic.txt (you have to read these from the txt file) Miles per gallon: 20 Tank Size (in gallons): 25 Therefore, based on these...
C++ Read and do as instructed on please
(C++Program *** use only condition statements, loops, functions, files, and arrays. Do NOT use material such as classes. Make sure to add comments** You are to write an ATM Program. The ATM should allow the user to do the following: 1. Create account 2. Log in 3. Exit When they press 1, they are asked for first name (capital first letter). Then it should ask for password. The computer should give the...
Use your Car class from the previous Programming Assignment. For this assignment, create a new class that represents a Used Car Dealership. Your Java program will simulate an inventory system for the dealership, where the employees can manage the car information. Start by creating an array of 10 cars, with an "ID" of 0 through 9, and use the default constructor to create each car. For example, the third car in an array called cars would have ID 2. You...
Write a java program that creates a class Car. Class Car contains the following private member fields: make, model, year, and miles. The class Car has a constructor that takes as arguments the car make, model, and year. In addition, the constructor sets miles to 100 as default. Class Car has accessors and mutators to get and set the make, model, year and miles on the car. The program should complete the following tasks: Ask the user to enter make,...