implement all todo tasks in ElectricCar.java
This commit is contained in:
@@ -26,13 +26,36 @@ public class ElectricCar extends Car implements Chargeable {
|
|||||||
this.batteryCapacity = batteryCapacity;
|
this.batteryCapacity = batteryCapacity;
|
||||||
this.chargeLevel = chargeLevel;
|
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"
|
// 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()
|
// TODO: Override showDetails()
|
||||||
// Call super.showDetails()
|
// Call super.showDetails()
|
||||||
// Print battery capacity and charge level
|
// 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)
|
// TODO: Implement charge(double amount)
|
||||||
// Validate negative
|
// Validate negative
|
||||||
// Cap at 100
|
// Cap at 100
|
||||||
|
|||||||
Reference in New Issue
Block a user