complete workshop assignments

This commit is contained in:
amirM.t
2026-04-28 09:12:10 +03:30
parent e8aedb8354
commit 1a78323743
7 changed files with 222 additions and 155 deletions
+18 -6
View File
@@ -20,15 +20,27 @@ public abstract class Vehicle {
this.mileage = mileage;
}
// TODO: Create getters for all fields
public String getBrand() {return brand;}
// TODO: Implement addMileage(double km)
// If km is negative → print error
// Otherwise increase mileage
public String getModel() {return model;}
// TODO: Declare abstract method getEnergyType()
public int getYear() {return year;}
public void basicInfo() {
public double getMileage() {return mileage;}
public void addMileage(double km)
{
if (km < 0)
System.out.println("Error: Mileage cannot be negative.");
else
this.mileage += km;
}
public abstract String getEnergyType();
public void basicInfo()
{
System.out.println(
year + " " + brand + " " + model +
" | Mileage: " + mileage +