implement bonus task (HybeidCar.java)
This commit is contained in:
@@ -1,4 +1,44 @@
|
||||
package org.model;
|
||||
|
||||
public class HybridCar {
|
||||
import org.behavior.Chargeable;
|
||||
import org.behavior.Refuelable;
|
||||
|
||||
public class HybridCar extends Car implements Chargeable, Refuelable {
|
||||
private int batteryCapacity;
|
||||
private double chargeLevel;
|
||||
private double fuelLevel;
|
||||
private String fuelType;
|
||||
|
||||
public HybridCar(String brand, String model, int year, double mileage,
|
||||
int seats, int batteryCapacity, double chargeLevel,
|
||||
double fuelLevel, String fuelType) {
|
||||
super(brand, model, year, mileage, seats);
|
||||
this.batteryCapacity = batteryCapacity;
|
||||
this.chargeLevel = chargeLevel;
|
||||
this.fuelLevel = fuelLevel;
|
||||
this.fuelType = fuelType;
|
||||
}
|
||||
|
||||
public boolean needsService(Vehicle v) {
|
||||
return v.getMileage() > 10000;
|
||||
}
|
||||
public void performService() {
|
||||
System.out.println("Engine oil changed and battery system checked");
|
||||
this.chargeLevel = 100;
|
||||
this.fuelLevel = 100;
|
||||
}
|
||||
public void charge(double amount) {
|
||||
if (amount > 0 && this.chargeLevel + amount <= 100) {
|
||||
this.chargeLevel += amount;
|
||||
} else if (amount > 0 && this.chargeLevel + amount > 100) {
|
||||
this.chargeLevel = 100; //if input amount causes the battery to charge pass 100%, we set it to 100%.
|
||||
}
|
||||
}
|
||||
public void refuel(double amount) {
|
||||
if (amount > 0 && this.fuelLevel + amount <= 100) {
|
||||
this.fuelLevel += amount;
|
||||
} else if (amount > 0 && this.fuelLevel + amount > 100) {
|
||||
this.fuelLevel = 100; //if input amount causes the fuel to fill pass 100%, we set it to 100%.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user