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:
parent
6367b48746
commit
ee94355f42
@ -14,6 +14,11 @@ public class Bus extends CivilVehicle {
|
||||
generateUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSpeed() {
|
||||
return MAX_FORWARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrive() {
|
||||
super.arrive();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -10,6 +10,11 @@ public class SUV extends CivilVehicle {
|
||||
generateUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSpeed() {
|
||||
return MAX_FORWARD;
|
||||
}
|
||||
|
||||
public int getTimeToFix(){
|
||||
return TIME_TO_FIX;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -12,6 +12,8 @@ public abstract class Vehicle {
|
||||
private Date timeStartedMoving;
|
||||
private Date timeOfArrival;
|
||||
|
||||
public abstract int getMaxSpeed();
|
||||
|
||||
public Vehicle(double vehicleSize){
|
||||
setVehicleSize(vehicleSize);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user