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" @Override public String getEnergyType() { return "Electric"; } // TODO: Override showDetails() @Override public void showDetails() { super.showDetails(); System.out.printf(", Battery Capacity: %s, Charge Level: %s", batteryCapacity, chargeLevel); } // TODO: Implement charge(double amount) @Override public void charge(double amount) { if(amount < 0){ System.out.println("Error: can\'t add negative number!"); return; } if(chargeLevel + amount <= 100){ chargeLevel += amount; } } @Override public boolean needsService(Vehicle v) { return getMileage() > 8000; } @Override public void performService() { System.out.println("Battery system checked"); chargeLevel = 100; } }