]> Git Server - tankstelle.git/commitdiff
Added two methods: isPINCorrect to check if a PIN given is the same as the content...
authorRobin Cheney <cheneyr@eternal.ddnss.de>
Sun, 16 Nov 2025 08:58:26 +0000 (09:58 +0100)
committerRobin Cheney <cheneyr@eternal.ddnss.de>
Sun, 16 Nov 2025 08:58:26 +0000 (09:58 +0100)
src/main/java/de/diejungsvondertanke/tankstelle/Main.java
src/main/resources/pin.txt [new file with mode: 0644]

index d028e5b1c98bc88486eec0fab35ea22993bd7939..8ac4cdbdb574ddf645a008d593759398d053781d 100644 (file)
@@ -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<FuelStation> 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 (file)
index 0000000..4632e06
--- /dev/null
@@ -0,0 +1 @@
+123456
\ No newline at end of file