Implemented all of the TODO sections, Added HybridCar class and its methods, removed comments.

This commit is contained in:
2026-04-27 00:04:49 +03:30
parent e8aedb8354
commit 33a11d54c7
8 changed files with 214 additions and 193 deletions
+33 -16
View File
@@ -1,16 +1,5 @@
package org.model;
/*
* ElectricCar extends Car.
* It already inherits Serviceable from Car.
*
* Service logic for ElectricCar:
* - needsService(): return true if mileage > 8000
* - performService():
* Print "Battery system checked"
* Reset chargeLevel to 100
*/
import org.behavior.Chargeable;
public class ElectricCar extends Car implements Chargeable {
@@ -27,11 +16,39 @@ public class ElectricCar extends Car implements Chargeable {
this.chargeLevel = chargeLevel;
}
// TODO: Override getEnergyType() → return "Electric"
@Override
public String getEnergyType() {
return "Electric";
}
// TODO: Override showDetails()
@Override
public void showDetails() {
System.out.println("Battery capacity : " + this.batteryCapacity);
System.out.println("Charge level : " + this.chargeLevel);
}
// TODO: Implement charge(double amount)
// Validate negative
// Cap at 100
public void charge(double amount){
if (amount <= 0){
System.out.println("Charging amount should be positive.");
return;
}
if (chargeLevel + amount > 100){
System.out.println("Battery Full!");
return;
}
}
@Override
public boolean needsService(Vehicle v) {
if (v.getMileage() > 8000){
return true;
}
return false;
}
@Override
public void performService() {
System.out.println("Battery system checked");
this.chargeLevel = 100;
}
}