55 lines
1.3 KiB
Java
55 lines
1.3 KiB
Java
package org.model;
|
|
|
|
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;
|
|
}
|
|
|
|
@Override
|
|
public String getEnergyType() {
|
|
return "Electric";
|
|
}
|
|
|
|
@Override
|
|
public void showDetails() {
|
|
System.out.println("Battery capacity : " + this.batteryCapacity);
|
|
System.out.println("Charge level : " + this.chargeLevel);
|
|
}
|
|
|
|
public void charge(double amount){
|
|
if (amount <= 0){
|
|
System.out.println("Charging amount should be positive.");
|
|
return;
|
|
}
|
|
if (chargeLevel + amount > 100){
|
|
System.out.println("Battery Full!");
|
|
return;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean needsService(Vehicle v) {
|
|
if (v.getMileage() > 8000){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void performService() {
|
|
System.out.println("Battery system checked");
|
|
this.chargeLevel = 100;
|
|
}
|
|
}
|