In this exercise you'll be playing around with a remote controlled car, which you've finally saved enough money for to buy.
Cars start with full (100%) batteries. Each time you drive the car using the remote control, it covers 20 meters and drains one percent of the battery.
The remote controlled car has a fancy LED display that shows two bits of information:
"Driven <METERS> meters"."Battery at <PERCENTAGE>%".If the battery is at 0%, you can't drive the car anymore and the battery display will show "Battery empty".
You have six tasks, each of which will work with remote controlled car instances.
Implement the (static) JedliksToyCar.buy() method to return a brand-new remote controlled car instance:
JedliksToyCar car = JedliksToyCar.buy();Implement the JedliksToyCar.distanceDisplay() method to return the distance as displayed on the LED display:
JedliksToyCar car = JedliksToyCar.buy();
car.distanceDisplay();
// => "Driven 0 meters"Implement the JedliksToyCar.batteryDisplay() method to return the battery percentage as displayed on the LED display:
JedliksToyCar car = JedliksToyCar.buy();
car.batteryDisplay();
// => "Battery at 100%"Implement the JedliksToyCar.drive() method that updates the number of meters driven:
JedliksToyCar car = JedliksToyCar.buy();
car.drive();
car.drive();
car.distanceDisplay();
// => "Driven 40 meters"Update the JedliksToyCar.drive() method to update the battery percentage:
JedliksToyCar car = JedliksToyCar.buy();
car.drive();
car.drive();
car.batteryDisplay();
// => "Battery at 98%"Update the JedliksToyCar.drive() method to not increase the distance driven nor decrease the battery percentage when the battery is drained (at 0%):
JedliksToyCar car = JedliksToyCar.buy();
// Drain the battery
// ...
car.distanceDisplay();
// => "Driven 2000 meters"
car.batteryDisplay();
// => "Battery empty"In this exercise you'll be playing around with a remote controlled car, which you've finally saved enough money for to buy.
Cars start with full (100%) batteries. Each time you drive the car using the remote control, it covers 20 meters and drains one percent of the battery.
The remote controlled car has a fancy LED display that shows two bits of information:
"Driven <METERS> meters"."Battery at <PERCENTAGE>%".If the battery is at 0%, you can't drive the car anymore and the battery display will show "Battery empty".
You have six tasks, each of which will work with remote controlled car instances.
Implement the (static) JedliksToyCar.buy() method to return a brand-new remote controlled car instance:
JedliksToyCar car = JedliksToyCar.buy();Implement the JedliksToyCar.distanceDisplay() method to return the distance as displayed on the LED display:
JedliksToyCar car = JedliksToyCar.buy();
car.distanceDisplay();
// => "Driven 0 meters"Implement the JedliksToyCar.batteryDisplay() method to return the battery percentage as displayed on the LED display:
JedliksToyCar car = JedliksToyCar.buy();
car.batteryDisplay();
// => "Battery at 100%"Implement the JedliksToyCar.drive() method that updates the number of meters driven:
JedliksToyCar car = JedliksToyCar.buy();
car.drive();
car.drive();
car.distanceDisplay();
// => "Driven 40 meters"Update the JedliksToyCar.drive() method to update the battery percentage:
JedliksToyCar car = JedliksToyCar.buy();
car.drive();
car.drive();
car.batteryDisplay();
// => "Battery at 98%"Update the JedliksToyCar.drive() method to not increase the distance driven nor decrease the battery percentage when the battery is drained (at 0%):
JedliksToyCar car = JedliksToyCar.buy();
// Drain the battery
// ...
car.distanceDisplay();
// => "Driven 2000 meters"
car.batteryDisplay();
// => "Battery empty"