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), tank info: (current / max)) and mileage.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.
Please not that this exercies copies OOP week 1 exactly. It’s not the point to simply do the assignment again. (Simply copy the code/project from last time.) This time around we need you to write unittests that confirm that the car works as specified in the requirements:
Req.# | Description | Result |
---|---|---|
R01 | Upon creation car has a legal license plate | Untested |
R02 | Upon creation car has a full tank | Untested |
R04 | When you drive kilometers go up, and fuel goes down. | Untested |
R05 | When the tank is (nearly) empty, the car won’t drive. | Untested |
R06 | When the tank is full, no fuel may be added | Untested |
R07 | When the tank has room you can add some fuel | Untested |
R08 | When you call methods with illegal arguments, the right exception should be thrown. | Untested |