do tasks and learn OOP concepts like Interfaces, Inheritance, Polymorphism, and Abstraction.

This commit is contained in:
2026-07-12 16:14:12 +03:30
parent 6cb8f9a8d8
commit d571db3bc5
8 changed files with 217 additions and 138 deletions
+12 -5
View File
@@ -20,13 +20,20 @@ public abstract class Vehicle {
this.mileage = mileage;
}
// TODO: Create getters for all fields
public String getBrand() { return brand; }
public String getModel() { return model; }
public int getYear() { return year; }
public double getMileage() { return mileage; }
// TODO: Implement addMileage(double km)
// If km is negative → print error
// Otherwise increase mileage
public void addMileage(double km) {
if (km < 0) {
System.out.println("Error: mileage cannot be negative.");
} else {
mileage += km;
}
}
// TODO: Declare abstract method getEnergyType()
public abstract String getEnergyType();
public void basicInfo() {
System.out.println(