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
+28 -5
View File
@@ -20,13 +20,36 @@ public abstract class Vehicle {
this.mileage = mileage;
}
// TODO: Create getters for all fields
public String getBrand() {
// TODO: Implement addMileage(double km)
// If km is negative → print error
// Otherwise increase mileage
return brand;
}
// TODO: Declare abstract method getEnergyType()
public String getModel() {
return model;
}
public int getYear() {
return year;
}
public double getMileage() {
return mileage;
}
public void addMileage(double km) {
if ( km < 0 ) {
System.out.println("Error: Mileage cannot be negative!");
return;
}
this.mileage += km;
}
public abstract String getEnergyType();
public void basicInfo() {
System.out.println(