Vehicle toString():
- Print route - Check if street is null before getting name. Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
d7e3fd7a68
commit
3a91f2f0f1
10
src/Bus.java
10
src/Bus.java
@ -29,7 +29,15 @@ public class Bus extends CivilVehicle {
|
||||
public int getTimeToFix() {
|
||||
return TIME_TO_FIX;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(super.toString());
|
||||
s.append(String.format("ID: %s, Campaign ID: %s\n",this.getUID() , getCampaign().getUID()));
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
private void generateUID() {
|
||||
numeberOfBuses++;
|
||||
this.UID = String.format("BUS%04d", numeberOfBuses);
|
||||
|
@ -185,7 +185,8 @@ public class MakkahCity {
|
||||
String c = in.next();
|
||||
Vehicle v = listOfVehicles.get(Integer.parseInt(c));
|
||||
//TODO: override toString() in vehicle then Bus. This will throw cast ex.
|
||||
System.out.print(v.toString());
|
||||
System.out.print("\n\n"+v.toString()+"\n\n");
|
||||
//meybe add option here to go to members (Campaign, Street ...)
|
||||
}
|
||||
if (choice.equals("2")){
|
||||
for (int i = 0; i < stdStreet.length; i++) {
|
||||
|
@ -28,4 +28,9 @@ public class TrafficPoliceCar extends Vehicle implements CanBeGovtCar, CanFixAcc
|
||||
public int getMaxSpeed() {
|
||||
return Sedan.MAX_FORWARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUID() {
|
||||
return TPC_UID;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public abstract class Vehicle {
|
||||
private HashMap<Street, Integer> routeTimeHistory = new HashMap<>();
|
||||
|
||||
public abstract int getMaxSpeed();
|
||||
public abstract String getUID();
|
||||
|
||||
public Vehicle(double vehicleSize){
|
||||
setVehicleSize(vehicleSize);
|
||||
@ -168,9 +169,12 @@ public abstract class Vehicle {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("%s\nStreet: %s Location: %.1f\n" +
|
||||
Street st = this.currentStreet;
|
||||
String streetString = "null";
|
||||
if (st != null) streetString = st.getName().name();
|
||||
return String.format("%s\nRoute: %s\nStreet: %s, Location: %.1f\n" +
|
||||
"Arrived: %s Starting time: %s Arrive Time: %s\n",
|
||||
super.toString(), this.getCurrentStreet().getName().name(),
|
||||
super.toString(), this.route, streetString,
|
||||
this.getCurrentLocation(), this.isArrivedToDest(),
|
||||
this.getTimeStartedMoving(), this.getTimeOfArrival());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user