implement all todo tasks in ElectricCar.java

This commit is contained in:
2026-04-27 20:09:10 +03:30
parent 543ea063a7
commit 3d38464d34
+24 -1
View File
@@ -26,13 +26,36 @@ public class ElectricCar extends Car implements Chargeable {
this.batteryCapacity = batteryCapacity;
this.chargeLevel = chargeLevel;
}
public boolean needsService(Vehicle v) {
return v.getMileage() > 8000;
}
public void performService() {
System.out.println("Battery system checked");
this.chargeLevel = 100;
}
@Override
public String getEnergyType() {
return "Electric";
}
// TODO: Override getEnergyType() → return "Electric"
@Override
public void showDetails() {
super.showDetails();
System.out.println("Battery capacity: " + this.batteryCapacity + ", Charge level: " +
this.chargeLevel);
}
// TODO: Override showDetails()
// Call super.showDetails()
// Print battery capacity and charge level
public void charge(double amount) {
if (amount > 0 && this.chargeLevel + amount <= 100) {
this.chargeLevel += amount;
} else if (amount > 0 && this.chargeLevel + amount > 100) {
this.chargeLevel = 100; //if input amount causes the battery to charge pass 100%, we set it to 100%.
}
}
// TODO: Implement charge(double amount)
// Validate negative
// Cap at 100