From: Robin Cheney Date: Sun, 16 Nov 2025 08:58:26 +0000 (+0100) Subject: Added two methods: isPINCorrect to check if a PIN given is the same as the content... X-Git-Url: https://git.eternal.ddnss.de/?a=commitdiff_plain;h=c4266d87d79160cf7943078463f0f784b70e08f9;p=tankstelle.git Added two methods: isPINCorrect to check if a PIN given is the same as the content of pin.txt and getFuelStationListWhenUnderstaffed to return a list of fuel stations that can still be operated with the reduced amount of available staff --- diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/Main.java b/src/main/java/de/diejungsvondertanke/tankstelle/Main.java index d028e5b..8ac4cdb 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/Main.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/Main.java @@ -1,5 +1,8 @@ package de.diejungsvondertanke.tankstelle; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; @@ -92,4 +95,40 @@ public class Main { } return highestStation; } + + /** + * Check {@code pin} for the correct PIN number + * + * @param pin the PIN to check + * @return true, if the pin is correct, false otherwise + * @throws IOException if the configured file pin.txt was not found + */ + public static boolean isPINCorrect(String pin) throws IOException { + + BufferedReader bfro = new BufferedReader(new InputStreamReader(Main.class.getResourceAsStream("/pin.txt"))); + + if (bfro.readLine().trim().equals(pin.trim())) + return true; + else + return false; + } + + /** + * This function will, for any number of employees, return an array of + * {@link FuelStation}s that can be opened with the staff given + * + * @param available_employees number of employees available + * @return All fuel stations that can reasonably be opened today + */ + public static FuelStation[] getFuelStationListWhenUnderstaffed(short available_employees) { + ArrayList result = new ArrayList<>(); + FuelStation[] fuelStationsLocalCopy = FuelStation.sort(fuelStations); + for (FuelStation station : fuelStationsLocalCopy) { + if (Math.floorDiv(available_employees, station.getNumber_of_employees()) >= 1) { + available_employees -= station.getNumber_of_employees(); + result.add(station); + } + } + return result.toArray(new FuelStation[0]); + } } \ No newline at end of file diff --git a/src/main/resources/pin.txt b/src/main/resources/pin.txt new file mode 100644 index 0000000..4632e06 --- /dev/null +++ b/src/main/resources/pin.txt @@ -0,0 +1 @@ +123456 \ No newline at end of file