Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.
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 specif
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 the Car should be able to drive 20 x 25 = 500 miles.
Supply a method called Drive that simulates driving the car for a certain distance, reducing the fuel level in the gas tank, and methods getGasLevel, to return the current fuel level, and addGas, to tank up.
Sample usage:
myHybrid = Car(20) # 20 miles per gallon myHybrid.drive(100) # Drive 100 miles print(myHybrid.getGasLevel()) # Print fuel remaining myHybrid.addGas(9) # Add 9 gallons
Sample Scenario:
We know our car can drive 500 miles. If I use the myHybrid.drive(100)
function, it means Drive the Car
100 miles.
print(myHybrid.getGasLevel()) should Print the fuel remaining. How do you get that ?
500 (Car Max. miles ) – 100 (the miles you drove) = 400 (Car Max miles now) / 20 (Miles per gallon)
= 20 gallons remaining
If we call myHybrid.addGas(9) , i.e. Add 9 gallons – it should only add 5 gallons (as 20 is already in the tank and tank size is 25 gallons). On the other hand, If we call myHybrid.addGas(3), it should be fine. If tank is full and you try to add Gas, it should not add gas.
Note: You have to keep track of the variables, etc. (I am not telling you. Figure out how and which variables to keep yourself), and give appropriate messages.
Program Behavior
When the program starts User should see Miles per gallon: 20
Tank Size (in gallons): 25
(Note: these values are read from the file and are NOT hard-coded)
Then the program should show the MAIN MENU and ask the user what to do
What would you like to do:
1. See Current Fuel Level
2. Drive
3. Add Gas
4. Exit
If user inputs 1, program displays Current Fuel Level and returns to MAIN MENU
The program also writes/appends the user input and associated result to a log file called LogFuel.txt
If user inputs 2, program asks How many miles to Drive:
Let’s say user inputs 100. Program displays
You drove 100 miles. You can drive another 400 miles on this gas.
The program also writes/appends the user input and associated result to a log file called LogFuel.txt
If user inputs 3, program asks How much gas to Add:
Give the appropriate message, i.e. whether gas was added and how much.
The program also writes/appends the user input and associated result to a log file called LogFuel.txt
If user inputs 4, program exits
LogFuel.txt may look like the following
User Input: 1 - See Current Fuel Level Fuel level shown: 25 gallons
User Input: 2 – Drive
Miles to Drive: 100
User Input: 1 - See Current Fuel Level Fuel level shown: 20 gallons
User Input: 4 – Exit
Final Note: Do all Error Handling, e.g. not allowing to drive more miles than current maximum, not allowing to fill in more gas, etc.