Lab 2: the Car class
Create a Car class that stores gas left (as a double) in liters,
distance travelled (as an int) in kilometers,
and efficiency (as a double) in kilometers/liter.
Gas left and distance travelled starts at 0,
efficiency starts at 10 kilometers/liter.
Support the following methods:
- void loadGas( double liters )
- void drive( int km )
- double getGasLeft()
- int getOdometerReading()
- void changeEfficiency( double eff )
Use if statements in your methods to ensure that
- drive will work only if there is enough gas
optional: attempt to drive beyond capacity causes the car to drive
until the tank is empty
- loadGas will never cause a tank to go beyond
50 liters (tank's capacity)
optional: attempt to load gas beyond 50 liters will just fill the tank
- efficiency should only be between 0 and 50 km/liter
Write this program in BlueJ and test
the class by creating objects and running methods
on that object.
Zip your BlueJ project and submit through
moodle .
Make sure you have your name and a class description written in your class
and your zip file is named Lab2xxxxxx.zip, where xxxxxx is your id number.