Vehicle toString()

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2020-11-30 21:05:01 +03:00
parent 2edf82b28b
commit d7e3fd7a68
Signed by: Hesham
GPG Key ID: 74876157D199B09E
2 changed files with 9 additions and 5 deletions

View File

@ -185,10 +185,7 @@ 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.printf("%s\n Campaign: %s Street: %s Location: %.1f\n" +
"Arrived: %s Starting time: %s Arrive Time: %s\n",
v.toString(), ((Bus)v).getCampaign().getUID(),v.getCurrentStreet().getName().name(),
v.getCurrentLocation(),v.isArrivedToDest(),v.getTimeStartedMoving(),v.getTimeOfArrival());
System.out.print(v.toString());
}
if (choice.equals("2")){
for (int i = 0; i < stdStreet.length; i++) {

View File

@ -166,7 +166,14 @@ public abstract class Vehicle {
public boolean hasCrossedStreet(Street street) {
return routeTimeHistory.containsKey(street);
}
public String toString() {
return String.format("%s\nStreet: %s Location: %.1f\n" +
"Arrived: %s Starting time: %s Arrive Time: %s\n",
super.toString(), this.getCurrentStreet().getName().name(),
this.getCurrentLocation(), this.isArrivedToDest(),
this.getTimeStartedMoving(), this.getTimeOfArrival());
}
}