Fixed cast error

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2020-12-02 18:29:24 +03:00
parent b6003cc3e8
commit 22ee69be52

View File

@ -207,16 +207,23 @@ public class MakkahCity {
private static void showVehicle(Vehicle vehicle) { private static void showVehicle(Vehicle vehicle) {
String choice = ""; String choice = "";
Scanner in = new Scanner(System.in); Scanner in = new Scanner(System.in);
Bus bus = (Bus) vehicle; //Should always be bus since 'View buses' StringBuilder menu = new StringBuilder();
System.out.print("\n\n"+vehicle.getUID()+"\n"); int opCount = 0;
System.out.println("---------------------------\n"+ menu.append("\n\n")
"[1] Details\n" + .append(vehicle.getUID())
"[2] Get Campaign\n" + .append("\n")
"[3] Return"); .append("---------------------------\n")
.append(String.format("[%d] Details\n",++opCount));
if (vehicle instanceof Bus) {
menu.append(String.format("[%d] Get Campaign\n", ++opCount));
}
menu.append(String.format("[%d] Return", ++opCount));
System.out.println(menu.toString());
choice = in.next(); choice = in.next();
if (choice.equals("1")) System.out.println(bus.toString()); if (choice.equals("1")) System.out.println(vehicle.toString());
if (choice.equals("2")) showCampaign(bus.getCampaign()); if (choice.equals("2") && opCount == 3) showCampaign(((Bus)vehicle).getCampaign());
if (choice.equals("3")) return; else if (choice.equals("2")) return;
else if (choice.equals("3")) return;
showVehicle(vehicle); showVehicle(vehicle);
} }