Output Color with respect to capacity

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2020-11-21 00:25:43 +03:00
parent 1efd3e2dec
commit da001dc5cd

View File

@ -471,12 +471,12 @@ public class MakkahCity {
"*********| District | Average Arrival\n";
String report = "";
report = report + String.format(headerFormat, currenttimeManager.getCurrentTime(), status);
String streetFormat = "%-18s | %%%-8s | %5d | %5d | %14d |";
String streetFormat = "%-27s | %%%-8s | %5d | %5d | %14d |";
String districtForamt = " | %-9s | %%%2d ";
for (int i = 0; i < stdStreet.length; i++) {
int cap = stdStreet[i].getPercentRemainingCapacity();
report = report + String.format(streetFormat,
stdStreet[i].getName().name(),
getColoredStreetName(stdStreet[i],cap),
cap,
stdStreet[i].getVehicles().size(),
stdStreet[i].getNumberOfBuses(),
@ -557,4 +557,23 @@ public class MakkahCity {
return true;
}
private static String getColoredStreetName(Street street, int capacity) {
String s = "";
String name = street.getName().name();
if (capacity > 80) s = ANSI_RED + name;
else if (capacity > 60) s = ANSI_YELLOW + name;
else s = ANSI_GREEN + name;
return s + ANSI_RESET;
}
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
}