From 3d38464d34644f091a2bc7771deb4806c0889d2f Mon Sep 17 00:00:00 2001 From: Saeed Jamali Date: Mon, 27 Apr 2026 20:09:10 +0330 Subject: [PATCH] implement all todo tasks in ElectricCar.java --- src/main/java/org/model/ElectricCar.java | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/model/ElectricCar.java b/src/main/java/org/model/ElectricCar.java index 2ee9bd8..840edef 100644 --- a/src/main/java/org/model/ElectricCar.java +++ b/src/main/java/org/model/ElectricCar.java @@ -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