completing TODO parts.

This commit is contained in:
2026-04-29 00:22:52 +03:30
parent 6cb8f9a8d8
commit 81b635df0c
7 changed files with 174 additions and 25 deletions
+23 -3
View File
@@ -18,9 +18,7 @@ public class ElectricCar extends Car implements Chargeable {
private int batteryCapacity;
private double chargeLevel;
public ElectricCar(String brand, String model, int year,
double mileage, int seats,
int batteryCapacity, double chargeLevel) {
public ElectricCar(String brand, String model, int year, double mileage, int seats, int batteryCapacity, double chargeLevel) {
super(brand, model, year, mileage, seats);
this.batteryCapacity = batteryCapacity;
@@ -29,11 +27,33 @@ 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 + " | charge level: " + chargeLevel);
}
// TODO: Implement charge(double amount)
// Validate negative
// Cap at 100
public void charge(double amount){
if(amount < 0)
System.out.println("amount unacceptable");
else{
if (chargeLevel + amount > 100)
chargeLevel = 100;
else
chargeLevel += amount;
}
}
}