commit everything at once like an amateur (the mandatory part + bonus part)
This commit is contained in:
@@ -1,21 +1,10 @@
|
||||
package org.model;
|
||||
|
||||
/*
|
||||
* ElectricCar extends Car.
|
||||
* It already inherits Serviceable from Car.
|
||||
*
|
||||
* Service logic for ElectricCar:
|
||||
* - needsService(): return true if mileage > 8000
|
||||
* - performService():
|
||||
* Print "Battery system checked"
|
||||
* Reset chargeLevel to 100
|
||||
*/
|
||||
|
||||
import org.behavior.Chargeable;
|
||||
|
||||
public class ElectricCar extends Car implements Chargeable {
|
||||
|
||||
private int batteryCapacity;
|
||||
private final int batteryCapacity;
|
||||
private double chargeLevel;
|
||||
|
||||
public ElectricCar(String brand, String model, int year,
|
||||
@@ -27,13 +16,47 @@ public class ElectricCar extends Car implements Chargeable {
|
||||
this.chargeLevel = chargeLevel;
|
||||
}
|
||||
|
||||
// TODO: Override getEnergyType() → return "Electric"
|
||||
@Override
|
||||
public String getEnergyType() {
|
||||
return "Electric";
|
||||
}
|
||||
|
||||
// TODO: Override showDetails()
|
||||
// Call super.showDetails()
|
||||
// Print battery capacity and charge level
|
||||
@Override
|
||||
public void showDetails()
|
||||
{
|
||||
super.showDetails();
|
||||
|
||||
// TODO: Implement charge(double amount)
|
||||
// Validate negative
|
||||
// Cap at 100
|
||||
System.out.println(
|
||||
"Battery capacity: " + batteryCapacity +
|
||||
"| Charge level: " + chargeLevel
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void charge(double amount) {
|
||||
if (amount <= 0) {
|
||||
System.out.println("An error occurred while charging the vehicle, value must be bigger than zero, " + amount + " is not");
|
||||
}
|
||||
|
||||
if (chargeLevel + amount > 100) {
|
||||
System.out.println("An error occurred while charging the vehicle, by adding this amount: " + amount + " vehicle's charge level exceeds battery capacity");
|
||||
}
|
||||
|
||||
chargeLevel += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performService() {
|
||||
super.performService();
|
||||
|
||||
System.out.println("Battery system checked");
|
||||
|
||||
chargeLevel = 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsService(Vehicle v) {
|
||||
return getMileage() > 8000;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user