Implemented all of the TODO sections, Added HybridCar class and its methods, removed comments.
This commit is contained in:
@@ -1,16 +1,5 @@
|
||||
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 {
|
||||
@@ -27,11 +16,39 @@ public class ElectricCar extends Car implements Chargeable {
|
||||
this.chargeLevel = chargeLevel;
|
||||
}
|
||||
|
||||
// TODO: Override getEnergyType() → return "Electric"
|
||||
@Override
|
||||
public String getEnergyType() {
|
||||
return "Electric";
|
||||
}
|
||||
|
||||
// TODO: Override showDetails()
|
||||
@Override
|
||||
public void showDetails() {
|
||||
System.out.println("Battery capacity : " + this.batteryCapacity);
|
||||
System.out.println("Charge level : " + this.chargeLevel);
|
||||
}
|
||||
|
||||
// TODO: Implement charge(double amount)
|
||||
// Validate negative
|
||||
// Cap at 100
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user