implement Vehicle.java

This commit is contained in:
2026-04-27 05:36:12 +03:30
parent 6cb8f9a8d8
commit 89b43d8a0d
+28 -3
View File
@@ -20,13 +20,38 @@ public abstract class Vehicle {
this.mileage = mileage;
}
// TODO: Create getters for all fields
// TODO: Implement addMileage(double km)
public String getBrand() {
return this.brand;
}
public String getModel() {
return this.model;
}
public int getYear() {
return this.year;
}
public double getMileage() {
return this.mileage;
}
// If km is negative → print error
// Otherwise increase mileage
public void addMileage(double km) {
if(km<0) {
System.out.print("km cannot be negative");
}
else {
this.mileage += km;
}
}
public abstract String getEnergyType();
// TODO: Declare abstract method getEnergyType()
public void basicInfo() {
System.out.println(