develop #1

Open
HadiSharifi wants to merge 8 commits from develop into master
5 changed files with 64 additions and 10 deletions
Showing only changes of commit 4cff34b20a - Show all commits
+2 -1
View File
@@ -1,5 +1,7 @@
package org; package org;
import org.model.HybridCar;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
@@ -20,7 +22,6 @@ public class Main {
// ============================================================ // ============================================================
// TODO 2: // TODO 2:
// Create an array of Vehicle: // Create an array of Vehicle:
-8
View File
@@ -1,13 +1,5 @@
package org.model; package org.model;
/*
* Car extends Vehicle.
* This class SHOULD implement Serviceable.
*
* Service logic for Car:
* - needsService(): return true if mileage > 10,000
* - performService(): print "General car service completed"
*/
import org.behavior.Serviceable; import org.behavior.Serviceable;
+57
View File
@@ -0,0 +1,57 @@
package org.model;
import org.behavior.Chargeable;
import org.behavior.Refuelable;
public class HybridCar extends Car implements Refuelable, Chargeable {
private double batteryLevel;
private double fuelLevel;
public HybridCar(String brand, String model, int year,
double mileage, int seats, double batteryLevel, double fuelLevel) {
super(brand, model, year, mileage, seats);
this.batteryLevel = batteryLevel;
this.fuelLevel = fuelLevel;
}
@Override
public String getEnergyType() {
return "Hybrid";
}
@Override
public void showDetails() {
super.showDetails();
System.out.println(
"Battery Level: " + this.batteryLevel + "\n"
+ "Fuel Level: " + this.fuelLevel
);
}
@Override
public void charge(double amount) {
if (amount < 0) {
throw new IllegalArgumentException("Amount must be positive");
}
if (this.batteryLevel + amount > 100) {this.batteryLevel = 100;}
this.batteryLevel += amount;
}
@Override
public void refuel(double amount) {
if (amount < 0) {
throw new IllegalArgumentException("Amount must be positive");
}
if (this.fuelLevel + amount > 100) {this.fuelLevel = 100;}
this.fuelLevel += amount;
}
@Override
public void performService() {
System.out.println("Engine oil changed and batter system checked");
this.batteryLevel = 100;
this.fuelLevel = 100;
}
}
@@ -3,6 +3,7 @@ package org.util;
import org.*; import org.*;
import org.model.ElectricCar; import org.model.ElectricCar;
import org.model.GasCar; import org.model.GasCar;
import org.model.HybridCar;
import org.model.SportsCar; import org.model.SportsCar;
import org.model.Vehicle; import org.model.Vehicle;
@@ -23,5 +24,8 @@ public class VehicleInspector {
else if (v instanceof GasCar) { else if (v instanceof GasCar) {
System.out.println("Check engine and oil"); System.out.println("Check engine and oil");
} }
else if (v instanceof HybridCar) {
System.out.println("Check engine and oil and battery service");
}
} }
} }