develop #1
@@ -1,4 +1,10 @@
|
||||
package org;
|
||||
import org.model.*;
|
||||
import org.util.VehicleInspector;
|
||||
import org.model.Vehicle;
|
||||
import org.util.VehicleInspector;
|
||||
|
||||
import org.behavior.Serviceable;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
@@ -84,6 +90,10 @@ public class Main {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ============================================================
|
||||
// TODO 6:
|
||||
// Loop through the Serviceable[] array:
|
||||
@@ -118,9 +128,43 @@ public class Main {
|
||||
//
|
||||
// ============================================================
|
||||
|
||||
Serviceable tesla = new ElectricCar("Tesla", "Model 3", 2023, 5000, 5, 75, 80);
|
||||
Serviceable honda = new GasCar("Honda", "Civic", 2022, 15000, 5, 50, "Gasoline");
|
||||
Serviceable porsche = new SportsCar("Porsche", "911", 2023, 2000, 2, 60, "Gasoline", 3.5);
|
||||
|
||||
|
||||
Vehicle[] vehicles = {(Vehicle) tesla, (Vehicle) honda, (Vehicle) porsche};
|
||||
|
||||
|
||||
for (Vehicle v : vehicles) {
|
||||
v.basicInfo();
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
for (Vehicle v : vehicles) {
|
||||
|
||||
VehicleInspector.inspect(v);
|
||||
}
|
||||
|
||||
|
||||
Serviceable[] serviceables = { tesla, honda, porsche };
|
||||
|
||||
|
||||
for (Serviceable s : serviceables) {
|
||||
Vehicle v = (Vehicle) s;
|
||||
if (s.needsService(v)) {
|
||||
System.out.println(v.GetBrand() + " " + v.GetBrand() + " needs service.");
|
||||
s.performService();
|
||||
} else {
|
||||
System.out.println(v.GetBrand() + " " + v.GetModel() + " does not need service.");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
System.out.println("=== Workshop Completed ===");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ package org.model;
|
||||
|
||||
import org.behavior.Serviceable;
|
||||
|
||||
public abstract class Car extends Vehicle implements Serviceable {
|
||||
public abstract class Car extends org.model.Vehicle implements Serviceable {
|
||||
|
||||
private int seats;
|
||||
|
||||
@@ -54,11 +54,14 @@ public abstract class Car extends Vehicle implements Serviceable {
|
||||
* - Print: "General car service completed"
|
||||
*/
|
||||
@Override
|
||||
public boolean needsService(Vehicle v)
|
||||
public boolean needsService(org.model.Vehicle v)
|
||||
{
|
||||
return this.GetMileage() > 10000 ;
|
||||
}
|
||||
@Override void performService(){
|
||||
|
||||
public abstract boolean needService(org.model.Vehicle v);
|
||||
|
||||
@Override public void performService(){
|
||||
System.out.println("General car service completed") ;
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ public class ElectricCar extends Car implements Chargeable {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean needService(vehicle v)
|
||||
public boolean needService(org.model.Vehicle v)
|
||||
{
|
||||
return (this.Getmileage()> 8000)
|
||||
return (this.GetMileage()> 8000);
|
||||
}
|
||||
@Override
|
||||
public void performService()
|
||||
@@ -31,6 +31,12 @@ public class GasCar extends Car implements Refuelable {
|
||||
{
|
||||
return this.GetMileage()> 12000 ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needService(Vehicle v) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performService()
|
||||
{
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.model;
|
||||
import org.behavior.Chargeable;
|
||||
import org.behavior.Refuelable;
|
||||
import org.model.Vehicle;
|
||||
|
||||
public class HybridCar extends Car implements Chargeable , Refuelable {
|
||||
|
||||
private int batteryCapacity;
|
||||
@@ -34,6 +36,12 @@ public class HybridCar extends Car implements Chargeable , Refuelable {
|
||||
System.out.println("fuel level : " + fuelLevel) ;
|
||||
System.out.println("fuel type : " + fuelType) ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needService(Vehicle v) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void charge(double amount)
|
||||
{
|
||||
@@ -9,7 +9,7 @@ package org.model;
|
||||
* Print "High-performance brake system checked"
|
||||
*/
|
||||
|
||||
public class SportsCar extends GasCar {
|
||||
public class SportsCar extends org.model.GasCar {
|
||||
|
||||
private double zeroToHundred;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class SportsCar extends GasCar {
|
||||
this.zeroToHundred = zeroToHundred;
|
||||
}
|
||||
@Override
|
||||
public boolean needsService(Vehicle v)
|
||||
public boolean needsService(org.model.Vehicle v)
|
||||
{
|
||||
return this.GetMileage() > 5000 ;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class SportsCar extends GasCar {
|
||||
@Override
|
||||
public void showDetails()
|
||||
{
|
||||
System.out.println("*details*")
|
||||
System.out.println("*details*");
|
||||
super.showDetails() ;
|
||||
System.out.println("0 --> 100 " + zeroToHundred) ;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.util;
|
||||
|
||||
import org.*;
|
||||
import org.model.*;
|
||||
import org.model.Vehicle;
|
||||
|
||||
/*
|
||||
Reference in New Issue
Block a user