Method in route getFastestTimeOfTravel(Vehicle):

- Every subclass of Vehicle needs to return
    the max of it self.

    - Calculate best case (empty streets) for
    a given vehcile using a Route.
This commit is contained in:
HeshamTB 2020-11-23 01:20:48 +03:00
parent 6367b48746
commit ee94355f42
Signed by: Hesham
GPG Key ID: 74876157D199B09E
7 changed files with 37 additions and 5 deletions

View File

@ -14,6 +14,11 @@ public class Bus extends CivilVehicle {
generateUID();
}
@Override
public int getMaxSpeed() {
return MAX_FORWARD;
}
@Override
public void arrive() {
super.arrive();

View File

@ -34,6 +34,14 @@ public class Route {
return totalLength;
}
public String getFastestTimeOfTravel(Vehicle vehicle) {
double totalLength = getTotalLength();
int maxSpeed = vehicle.getMaxSpeed();
int totalTime = (int) (totalLength/maxSpeed);
String result = String.format("%2d:%2d",totalTime % 60, totalTime /60);
return result;
}
public District getHotelArea() {
return hotelArea;
}

View File

@ -10,6 +10,11 @@ public class SUV extends CivilVehicle {
generateUID();
}
@Override
public int getMaxSpeed() {
return MAX_FORWARD;
}
public int getTimeToFix(){
return TIME_TO_FIX;
}

View File

@ -10,10 +10,9 @@ public class Sedan extends CivilVehicle {
super(vehicleSize);
generateUID();
}
@Override
public int getTimeToFix(){ return TIME_TO_FIX;
}
public int getTimeToFix(){ return TIME_TO_FIX; }
private void generateUID() {
numeberOfSedan++;
@ -24,7 +23,9 @@ public class Sedan extends CivilVehicle {
public String getUID(){
return this.UID;
}
@Override
public int getMaxSpeed() {
return MAX_FORWARD;
}
}

View File

@ -23,4 +23,9 @@ public class TrafficPoliceCar extends Vehicle implements CanBeGovtCar, CanFixAcc
public String getGovtID() {
return this.TPC_UID;
}
@Override
public int getMaxSpeed() {
return Sedan.MAX_FORWARD;
}
}

View File

@ -3,6 +3,12 @@ public class Truck extends CivilVehicle {
private String UID;
private static int numeberOfTruck;
private final int TIME_TO_FIX = 20; //in minutes
@Override
public int getMaxSpeed() {
return Bus.MAX_FORWARD;
}
public Truck(double vehicleSize){
super(vehicleSize);
generateUID();

View File

@ -12,6 +12,8 @@ public abstract class Vehicle {
private Date timeStartedMoving;
private Date timeOfArrival;
public abstract int getMaxSpeed();
public Vehicle(double vehicleSize){
setVehicleSize(vehicleSize);
}