implement todos for GasCar.java

This commit is contained in:
2026-04-27 20:40:42 +03:30
parent 3d38464d34
commit e9168db124
+25
View File
@@ -27,12 +27,37 @@ public class GasCar extends Car implements Refuelable {
this.fuelType = fuelType;
}
public boolean needsService(Vehicle v) {
return v.getMileage() > 8000;
}
public void performService() {
System.out.println("Engine oil changed");
this.fuelLevel = 100;
}
@Override
public String getEnergyType() {
return this.fuelType + " (Gas)";
}
// TODO: Override getEnergyType() → return fuelType + " (Gas)"
public void refuel(double amount) {
if (amount > 0 && this.fuelLevel + amount <= 100) {
this.fuelLevel += amount;
} else if (amount > 0 && this.fuelLevel + amount > 100) {
this.fuelLevel = 100; //if input amount causes the fuel to fill pass 100%, we set it to 100%.
}
}
// TODO: Implement refuel(double amount)
// Validate amount
// Cap at 100
@Override
public void showDetails() {
super.showDetails();
System.out.println("Feul level: " + this.fuelLevel + ", Feul type: " + this.fuelType);
}
// TODO: Override showDetails()
// Call super.showDetails()
// Print fuel level and fuel type