complete to do codes

This commit is contained in:
2026-04-30 12:06:26 +03:30
parent 6cb8f9a8d8
commit 2d6c7be01e
7 changed files with 172 additions and 1 deletions
+25
View File
@@ -28,12 +28,37 @@ public class ElectricCar extends Car implements Chargeable {
}
// 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();
System.out.println("Battery Capacity: " + batteryCapacity + " kWh");
System.out.println("Charge Level: " + chargeLevel + "%");
}
// TODO: Implement charge(double amount)
// Validate negative
// Cap at 100
@Override
public void charge(double amount) {
if (amount < 0) {
System.out.println("Charge amount cannot be negative.");
return;
}
chargeLevel += amount;
if (chargeLevel > 100) {
chargeLevel = 100;
}
System.out.println("Car charged. Current charge level: " + chargeLevel + "%");
}
}