We are going to build a class and implement methods to simulate the use of a new car. Read through all the requirements before you start building!
Create a car class that includes the following characteristics: brand, license plate, tank size in litres, current tank position, fuel consumption (consumption 16 means 16 km on 1 litre of petrol) and mileage.
Car
class is created, the tank must be full and the mileage reading must be set to 0.drive(int km)
: This method simulates that the car is driving. Based on the number of kilometres driven, the amount of petrol in the tank decreases (and the odometer reading increases). When the tank is empty, the car stops.fuel(int litres)
: This method simulates that the tank is refilled. Note that the tank cannot be refilled beyond the maximum tank size.toString()
method that produces the next string: brand (license plate), current fuel level (both in litres and in percentage) and mileage, where fuelPercentage is calculated as currentFuelLevel / maxFuelLevel.For this exercise we intentionally left the class diagram partially open. This means that you can decide what attributes and (helper) methods you might want to add.