Files
WS-03-advanced-oop-Ramtin/src/main/java/org/model/ElectricCar.java
T

63 lines
1.6 KiB
Java

package org.model;
import org.behavior.Chargeable;
public class ElectricCar extends Car implements Chargeable {
private final 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()
{
super.showDetails();
System.out.println(
"Battery capacity: " + batteryCapacity +
"| Charge level: " + chargeLevel
);
}
@Override
public void charge(double amount) {
if (amount <= 0) {
System.out.println("An error occurred while charging the vehicle, value must be bigger than zero, " + amount + " is not");
}
if (chargeLevel + amount > 100) {
System.out.println("An error occurred while charging the vehicle, by adding this amount: " + amount + " vehicle's charge level exceeds battery capacity");
}
chargeLevel += amount;
}
@Override
public void performService() {
super.performService();
System.out.println("Battery system checked");
chargeLevel = 100;
}
@Override
public boolean needsService(Vehicle v) {
return getMileage() > 8000;
}
}