Complete VMS with polymorphism demonstration

This commit is contained in:
2026-05-24 22:48:22 +03:30
parent 6cb8f9a8d8
commit 22726ea54d
8 changed files with 218 additions and 149 deletions
+41 -7
View File
@@ -27,13 +27,47 @@ public class GasCar extends Car implements Refuelable {
this.fuelType = fuelType;
}
// TODO: Override getEnergyType() → return fuelType + " (Gas)"
@Override
public String getEnergyType() {
return fuelType + " (Gas)";
}
// TODO: Implement refuel(double amount)
// Validate amount
// Cap at 100
public void refuel(double amount) {
if (amount <= 0) {
System.out.println("Error");
return;
}
// TODO: Override showDetails()
// Call super.showDetails()
// Print fuel level and fuel type
if (this.fuelLevel + amount > 100) {
this.fuelLevel = 100;
} else {
this.fuelLevel += amount;
}
}
@Override
public void showDetails() {
super.showDetails();
System.out.print(
" | fuel type: " + fuelType +
" | fuel level: " + fuelLevel
);
System.out.println();
}
@Override
public boolean needsService(Vehicle v) {
if(getMileage() > 12000) {
return true;
}
else {
return false;
}
}
@Override
public void performService() {
System.out.println("Engine oil changed");
this.fuelLevel = 100;
}
}