← Back to Classes
Question 518
Drive With Fuel
Drive With Fuel
Write the whole Car class. The constructor stores make and fuel (litres, a float) and sets odometer to 0.0. Every 10 km burns 1 litre: drive(km) works out the litres needed as km / 10, prints exactly Not enough fuel and changes nothing when that is more than the tank holds, and otherwise takes the litres out of fuel and adds km to odometer; refuel(litres) adds to the tank. Do NOT write a main block or any top-level test code; the tests construct the class. Input: two lines, a distance in km and then litres to add, which the tests read as floats and apply as a drive then a refuel on a car with 5.0 litres, before printing the fuel and the odometer on separate lines.
Expected Output:
4.0 30.0
= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Classes
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.