Complete Car project implementation.
This commit is contained in:
@@ -13,27 +13,58 @@ package org.model;
|
||||
|
||||
import org.behavior.Chargeable;
|
||||
|
||||
public class ElectricCar extends Car implements 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) {
|
||||
|
||||
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()
|
||||
// Call super.showDetails()
|
||||
// Print battery capacity and charge level
|
||||
@Override
|
||||
public void showDetails(){
|
||||
super.showDetails();
|
||||
System.out.println("Battery Capacity: " + batteryCapacity + " kWh" + " | Charge Level: " + chargeLevel + "%"
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Implement charge(double amount)
|
||||
// Validate negative
|
||||
// Cap at 100
|
||||
@Override
|
||||
public void charge(double amount){
|
||||
if (amount < 0){
|
||||
System.out.println("Error: Cannot charge with negative amount.");
|
||||
return;
|
||||
}
|
||||
|
||||
chargeLevel += amount;
|
||||
|
||||
if (chargeLevel > 100){
|
||||
chargeLevel = 100;
|
||||
}
|
||||
|
||||
System.out.println("Charged. Current charge level: " + chargeLevel + "%");
|
||||
}
|
||||
@Override
|
||||
public boolean needsService(Vehicle v){
|
||||
return v.getMileage() > 8000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performService(){
|
||||
System.out.println("Battery system checked");
|
||||
chargeLevel = 100;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user