Refactor: remove example package
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package org.model;
|
||||
|
||||
/*
|
||||
* Car extends Vehicle.
|
||||
* This class SHOULD implement Serviceable.
|
||||
*
|
||||
* Service logic for Car:
|
||||
* - needsService(): return true if mileage > 10,000
|
||||
* - performService(): print "General car service completed"
|
||||
*/
|
||||
|
||||
import org.behavior.Serviceable;
|
||||
|
||||
public abstract class Car extends Vehicle implements Serviceable {
|
||||
|
||||
private int seats;
|
||||
|
||||
public Car(String brand, String model, int year,
|
||||
double mileage, int seats) {
|
||||
|
||||
// TODO: Call super constructor
|
||||
this.seats = seats;
|
||||
}
|
||||
|
||||
// TODO: Override getEnergyType() → return "Unknown"
|
||||
|
||||
// TODO: Override showDetails()
|
||||
|
||||
/*
|
||||
* Implement Serviceable methods:
|
||||
*
|
||||
* needsService(Vehicle v):
|
||||
* - Check the mileage of the current car
|
||||
* - If mileage > 10000 return true
|
||||
* - Otherwise return false
|
||||
*
|
||||
* performService():
|
||||
* - Print: "General car service completed"
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.model;
|
||||
|
||||
/*
|
||||
* ElectricCar extends Car.
|
||||
* It already inherits Serviceable from Car.
|
||||
*
|
||||
* Service logic for ElectricCar:
|
||||
* - needsService(): return true if mileage > 8000
|
||||
* - performService():
|
||||
* Print "Battery system checked"
|
||||
* Reset chargeLevel to 100
|
||||
*/
|
||||
|
||||
import org.behavior.Chargeable;
|
||||
|
||||
public class ElectricCar extends Car implements Chargeable {
|
||||
|
||||
private int batteryCapacity;
|
||||
private double chargeLevel;
|
||||
|
||||
public ElectricCar(String brand, String model, int year,
|
||||
double mileage, int seats,
|
||||
int batteryCapacity, double chargeLevel) {
|
||||
|
||||
super(brand, model, year, mileage, seats);
|
||||
this.batteryCapacity = batteryCapacity;
|
||||
this.chargeLevel = chargeLevel;
|
||||
}
|
||||
|
||||
// TODO: Override getEnergyType() → return "Electric"
|
||||
|
||||
// TODO: Override showDetails()
|
||||
|
||||
// TODO: Implement charge(double amount)
|
||||
// Validate negative
|
||||
// Cap at 100
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.model;
|
||||
|
||||
/*
|
||||
* GasCar extends Car.
|
||||
* Inherits Serviceable from Car.
|
||||
*
|
||||
* Service logic for GasCar:
|
||||
* - needsService(): return true if mileage > 12000
|
||||
* - performService():
|
||||
* Print "Engine oil changed"
|
||||
* Reset fuelLevel to 100
|
||||
*/
|
||||
|
||||
import org.behavior.Refuelable;
|
||||
|
||||
public class GasCar extends Car implements Refuelable {
|
||||
|
||||
private double fuelLevel;
|
||||
private String fuelType;
|
||||
|
||||
public GasCar(String brand, String model, int year,
|
||||
double mileage, int seats,
|
||||
double fuelLevel, String fuelType) {
|
||||
|
||||
super(brand, model, year, mileage, seats);
|
||||
this.fuelLevel = fuelLevel;
|
||||
this.fuelType = fuelType;
|
||||
}
|
||||
|
||||
// TODO: Override getEnergyType() → return fuelType + " (Gas)"
|
||||
|
||||
// TODO: Implement refuel(double amount)
|
||||
// Validate amount
|
||||
// Cap at 100
|
||||
|
||||
// TODO: Override showDetails()
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.model;
|
||||
|
||||
/*
|
||||
* SportsCar extends GasCar.
|
||||
*
|
||||
* Special service logic for SportsCar:
|
||||
* - needsService(): return true if mileage > 5000
|
||||
* - performService():
|
||||
* Print "High-performance brake system checked"
|
||||
*/
|
||||
|
||||
public class SportsCar extends GasCar {
|
||||
|
||||
private double zeroToHundred;
|
||||
|
||||
public SportsCar(String brand, String model, int year,
|
||||
double mileage, int seats,
|
||||
double fuelLevel, String fuelType,
|
||||
double zeroToHundred) {
|
||||
|
||||
super(brand, model, year, mileage, seats,
|
||||
fuelLevel, fuelType);
|
||||
|
||||
this.zeroToHundred = zeroToHundred;
|
||||
}
|
||||
|
||||
// TODO: Override showDetails()
|
||||
// Print header
|
||||
// Call super.showDetails()
|
||||
// Print acceleration time
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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 {
|
||||
|
||||
private String brand;
|
||||
private String model;
|
||||
private int year;
|
||||
private double mileage;
|
||||
|
||||
public Vehicle(String brand, String model, int year, double mileage) {
|
||||
this.brand = brand;
|
||||
this.model = model;
|
||||
this.year = year;
|
||||
this.mileage = mileage;
|
||||
}
|
||||
|
||||
// TODO: Create getters for all fields
|
||||
|
||||
// TODO: Implement addMileage(double km)
|
||||
// If km is negative → print error
|
||||
// Otherwise increase mileage
|
||||
|
||||
// TODO: Declare abstract method getEnergyType()
|
||||
|
||||
public void basicInfo() {
|
||||
System.out.println(
|
||||
year + " " + brand + " " + model +
|
||||
" | Mileage: " + mileage +
|
||||
" | Energy: " + getEnergyType()
|
||||
);
|
||||
}
|
||||
|
||||
public abstract void showDetails();
|
||||
}
|
||||
Reference in New Issue
Block a user