complete all TODO sections in Vehicle class
This commit is contained in:
@@ -1,10 +1,5 @@
|
|||||||
package org.model;
|
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 {
|
public abstract class Vehicle {
|
||||||
|
|
||||||
@@ -20,13 +15,18 @@ public abstract class Vehicle {
|
|||||||
this.mileage = mileage;
|
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)
|
public void addMileage(double mileage) {
|
||||||
// If km is negative → print error
|
if (mileage < 0) {
|
||||||
// Otherwise increase mileage
|
throw new IllegalArgumentException("Mileage cannot be negative");
|
||||||
|
}
|
||||||
|
this.mileage += mileage;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Declare abstract method getEnergyType()
|
|
||||||
|
|
||||||
public void basicInfo() {
|
public void basicInfo() {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
@@ -37,4 +37,5 @@ public abstract class Vehicle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract void showDetails();
|
public abstract void showDetails();
|
||||||
|
public abstract String getEnergyType();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user