From 7ffbe689bc32cbfea84bc8aa9bc3d29e735f898f Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 10 Jan 2021 23:48:22 +0300 Subject: [PATCH] Discard special cases for general implementation: Instead of checking instance of veh, use the abstract method getMaxSpeed() with a given factor. This should reduce redundant checks (Wasted CPU cycles). Thus, run is a tiny bit faster. --- src/MakkahCity.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/MakkahCity.java b/src/MakkahCity.java index 1ee30e5..aa474bc 100644 --- a/src/MakkahCity.java +++ b/src/MakkahCity.java @@ -520,10 +520,7 @@ public class MakkahCity { if (!vehicle.isArrivedToDest()) { double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(), vehicle.getCurrentLocation()+1000,vehicle)) ; - if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor ); - else if (vehicle instanceof Sedan) vehicle.move(Sedan.MAX_FORWARD * factor ); - else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD * factor ); - else if (vehicle instanceof Truck) vehicle.move(Bus.MAX_FORWARD * factor ); + vehicle.move(vehicle.getMaxSpeed()* factor); } } }