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();
|
generateUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxSpeed() {
|
||||||
|
return MAX_FORWARD;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void arrive() {
|
public void arrive() {
|
||||||
super.arrive();
|
super.arrive();
|
||||||
|
@ -34,6 +34,14 @@ public class Route {
|
|||||||
return totalLength;
|
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() {
|
public District getHotelArea() {
|
||||||
return hotelArea;
|
return hotelArea;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,11 @@ public class SUV extends CivilVehicle {
|
|||||||
generateUID();
|
generateUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxSpeed() {
|
||||||
|
return MAX_FORWARD;
|
||||||
|
}
|
||||||
|
|
||||||
public int getTimeToFix(){
|
public int getTimeToFix(){
|
||||||
return TIME_TO_FIX;
|
return TIME_TO_FIX;
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,9 @@ public class Sedan extends CivilVehicle {
|
|||||||
super(vehicleSize);
|
super(vehicleSize);
|
||||||
generateUID();
|
generateUID();
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public int getTimeToFix(){ return TIME_TO_FIX;
|
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public int getTimeToFix(){ return TIME_TO_FIX; }
|
||||||
|
|
||||||
private void generateUID() {
|
private void generateUID() {
|
||||||
numeberOfSedan++;
|
numeberOfSedan++;
|
||||||
@ -25,6 +24,8 @@ public class Sedan extends CivilVehicle {
|
|||||||
return this.UID;
|
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() {
|
public String getGovtID() {
|
||||||
return this.TPC_UID;
|
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 String UID;
|
||||||
private static int numeberOfTruck;
|
private static int numeberOfTruck;
|
||||||
private final int TIME_TO_FIX = 20; //in minutes
|
private final int TIME_TO_FIX = 20; //in minutes
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxSpeed() {
|
||||||
|
return Bus.MAX_FORWARD;
|
||||||
|
}
|
||||||
|
|
||||||
public Truck(double vehicleSize){
|
public Truck(double vehicleSize){
|
||||||
super(vehicleSize);
|
super(vehicleSize);
|
||||||
generateUID();
|
generateUID();
|
||||||
|
@ -12,6 +12,8 @@ public abstract class Vehicle {
|
|||||||
private Date timeStartedMoving;
|
private Date timeStartedMoving;
|
||||||
private Date timeOfArrival;
|
private Date timeOfArrival;
|
||||||
|
|
||||||
|
public abstract int getMaxSpeed();
|
||||||
|
|
||||||
public Vehicle(double vehicleSize){
|
public Vehicle(double vehicleSize){
|
||||||
setVehicleSize(vehicleSize);
|
setVehicleSize(vehicleSize);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user