complete all TODO sections in Vehicle class
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
package org.model;
|
||||
|
||||
/*
|
||||
* Abstract base class for all vehicles.
|
||||
* This class DOES NOT implement Serviceable.
|
||||
* Service behavior will be defined in concrete subclasses.
|
||||
*/
|
||||
|
||||
public abstract class Vehicle {
|
||||
|
||||
@@ -20,13 +15,18 @@ public abstract class Vehicle {
|
||||
this.mileage = mileage;
|
||||
}
|
||||
|
||||
// TODO: Create getters for all fields
|
||||
public String getBrand() { return this.brand; }
|
||||
public String getModel() { return this.model; }
|
||||
public int getYear() { return this.year; }
|
||||
public double getMileage() { return this.mileage; }
|
||||
|
||||
// TODO: Implement addMileage(double km)
|
||||
// If km is negative → print error
|
||||
// Otherwise increase mileage
|
||||
public void addMileage(double mileage) {
|
||||
if (mileage < 0) {
|
||||
throw new IllegalArgumentException("Mileage cannot be negative");
|
||||
}
|
||||
this.mileage += mileage;
|
||||
}
|
||||
|
||||
// TODO: Declare abstract method getEnergyType()
|
||||
|
||||
public void basicInfo() {
|
||||
System.out.println(
|
||||
@@ -37,4 +37,5 @@ public abstract class Vehicle {
|
||||
}
|
||||
|
||||
public abstract void showDetails();
|
||||
public abstract String getEnergyType();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user