]> Git Server - tankstelle.git/commitdiff
finished UnderstaffedTab
authorRobin Cheney <cheneyr@eternal.ddnss.de>
Sat, 22 Nov 2025 14:36:48 +0000 (15:36 +0100)
committerRobin Cheney <cheneyr@eternal.ddnss.de>
Sat, 22 Nov 2025 14:36:48 +0000 (15:36 +0100)
src/main/java/de/diejungsvondertanke/tankstelle/Fuel.java
src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java
src/main/java/de/diejungsvondertanke/tankstelle/Main.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/FuelStationUIController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/OverviewTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/UnderstaffedTabController.java [new file with mode: 0644]
src/main/resources/ui/FuelStationUI.fxml
src/main/resources/ui/StockTab.fxml
src/main/resources/ui/UnderstaffedTab.fxml [new file with mode: 0644]

index 2a1362759159b62f03750730839d085d33236361..91a502efda8907e5491c3a04169818a55b998d3d 100644 (file)
@@ -15,7 +15,7 @@ public class Fuel {
     /**
      * Currently stored amount of fuel in L
      */
-    private float stored_amount;
+    private double stored_amount;
 
     /**
      * Maximum fuel storage capacity in L
@@ -65,7 +65,7 @@ public class Fuel {
      * 
      * @author Robin Cheney
      */
-    public float getStored_amount() {
+    public double getStored_amount() {
         return stored_amount;
     }
 
@@ -76,7 +76,7 @@ public class Fuel {
      * 
      * @author Robin Cheney
      */
-    public void setStored_amount(float stored_amount) {
+    public void setStored_amount(double stored_amount) {
         this.stored_amount = stored_amount;
     }
 
index ac8f12293d971076c46095c541c6c8bbd56de739..ea74a37cd9f664367b142809fc8c52de131c140a 100644 (file)
@@ -62,7 +62,7 @@ public abstract class FuelStation {
      * 
      * @author Nils Göbbert
      */
-    public void set_stored_amount(float new_amount, FuelType type) throws NoSuchFuelTypeError {
+    public void set_stored_amount(double new_amount, FuelType type) throws NoSuchFuelTypeError {
         for (Fuel i : fuels) {
             if (i.FUEL_TYPE == type) {
                 i.setStored_amount(new_amount);
@@ -84,7 +84,7 @@ public abstract class FuelStation {
      * 
      * @author Nils Göbbert
      */
-    public void add_stored_amount(float new_amount, FuelType type) throws NoSuchFuelTypeError, ArithmeticException {
+    public void add_stored_amount(double new_amount, FuelType type) throws NoSuchFuelTypeError, ArithmeticException {
         for (Fuel i : fuels) {
             if (i.FUEL_TYPE == type) {
                 if (new_amount + i.getStored_amount() < 0) {
@@ -198,9 +198,9 @@ public abstract class FuelStation {
             }
 
         }
-        result.addAll(large);
-        result.addAll(medium);
         result.addAll(small);
+        result.addAll(medium);
+        result.addAll(large);
         return result.toArray(new FuelStation[0]);
     }
 
@@ -235,9 +235,10 @@ public abstract class FuelStation {
             }
 
         }
-        result.addAll(large);
-        result.addAll(medium);
         result.addAll(small);
+        result.addAll(medium);
+        result.addAll(large);
+        // System.out.print(result);
         return result.toArray(new FuelStation[0]);
     }
 
@@ -252,7 +253,7 @@ public abstract class FuelStation {
      * 
      * @author Nils Göbbert
      */
-    public float getStored_amount(FuelType fuel_type) throws NoSuchFuelTypeError {
+    public double getStored_amount(FuelType fuel_type) throws NoSuchFuelTypeError {
         for (Fuel i : fuels) {
             if (i.FUEL_TYPE == fuel_type) {
                 return i.getStored_amount();
index ff433b272908aa15fadd7ca307266e85113b96aa..6a9192426675a7e0630add3d0a09b62fe86fc3c0 100644 (file)
@@ -164,11 +164,11 @@ public class Main {
      */
     public static FuelStation getHighestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError {
         FuelStation highestStation = null;
-        float highestAmount = Float.NEGATIVE_INFINITY;
+        double highestAmount = Double.NEGATIVE_INFINITY;
 
         for (FuelStation fuelStation : fuelStations) {
             try {
-                float amount = fuelStation.getStored_amount(fuelType);
+                double amount = fuelStation.getStored_amount(fuelType);
                 if (amount > highestAmount) {
                     highestAmount = amount;
                     highestStation = fuelStation;
@@ -199,11 +199,11 @@ public class Main {
      */
     public static FuelStation getLowestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError {
         FuelStation lowestStation = null;
-        float lowestAmount = Float.POSITIVE_INFINITY;
+        double lowestAmount = Double.POSITIVE_INFINITY;
 
         for (FuelStation fuelStation : fuelStations) {
             try {
-                float amount = fuelStation.getStored_amount(fuelType);
+                double amount = fuelStation.getStored_amount(fuelType);
                 if (amount < lowestAmount) {
                     lowestAmount = amount;
                     lowestStation = fuelStation;
index f10ee65151066df862378a738868f6a02a046e54..4757243a5de9983b127ca89a92fdb27fa1990f15 100644 (file)
@@ -45,6 +45,8 @@ public class FuelStationUIController {
     private VBox newStationTabContainer;
     @FXML
     private BorderPane overviewTabContainer;
+    @FXML
+    private VBox understaffedTabContainer;
 
     // Controllers of included tabs
     private ResultTabController resultTabController;
@@ -53,6 +55,7 @@ public class FuelStationUIController {
     private SearchTabController searchTabController;
     private NewStationTabController newStationTabController;
     private OverviewTabController overviewTabController;
+    private UnderstaffedTabController understaffedTabController;
 
     /**
      * Automatically called initialize() function.
@@ -101,6 +104,11 @@ public class FuelStationUIController {
                         overviewTabController.setParentController(this);
                         // overviewTabController.refresh();
                     });
+            loadTab("/ui/UnderstaffedTab.fxml", understaffedTabContainer,
+                    (UnderstaffedTabController c) -> {
+                        understaffedTabController = c;
+                        understaffedTabController.setParentController(this);
+                    });
         } catch (Exception e) {
             e.printStackTrace();
             // TODO: handle exception
index eb25b1450982dfa8fbac23acf0f6f325de368030..1cde85ebcd5bdac0f7b612fd1324e4fa6d740ba5 100644 (file)
@@ -7,6 +7,7 @@ import javafx.application.Platform;
 import javafx.beans.property.SimpleFloatProperty;
 import javafx.beans.property.SimpleIntegerProperty;
 import javafx.beans.property.SimpleStringProperty;
+import javafx.beans.property.SimpleDoubleProperty;
 import javafx.fxml.FXML;
 import javafx.scene.Node;
 import javafx.scene.Parent;
@@ -25,7 +26,7 @@ public class OverviewTabController {
     @FXML
     private TableColumn<FuelRow, String> colFuel;
     @FXML
-    private TableColumn<FuelRow, Float> colAmount;
+    private TableColumn<FuelRow, Double> colAmount;
     @FXML
     private TableColumn<FuelRow, Integer> colCapacity;
     @FXML
@@ -43,7 +44,7 @@ public class OverviewTabController {
         colStation.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getStation()));
         colType.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getType()));
         colFuel.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getFuel()));
-        colAmount.setCellValueFactory(data -> new SimpleFloatProperty(data.getValue().getAmount()).asObject());
+        colAmount.setCellValueFactory(data -> new SimpleDoubleProperty(data.getValue().getAmount()).asObject());
         colCapacity.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getCapacity()).asObject());
         colPrice.setCellValueFactory(data -> new SimpleFloatProperty(data.getValue().getPrice()).asObject());
     }
@@ -103,7 +104,7 @@ public class OverviewTabController {
         String station;
         String type;
         String fuel;
-        float amount;
+        double amount;
         int capacity;
         float price;
 
@@ -131,11 +132,11 @@ public class OverviewTabController {
             this.fuel = fuel;
         }
 
-        public float getAmount() {
+        public double getAmount() {
             return amount;
         }
 
-        public void setAmount(float amount) {
+        public void setAmount(double amount) {
             this.amount = amount;
         }
 
@@ -155,7 +156,7 @@ public class OverviewTabController {
             this.price = price;
         }
 
-        public FuelRow(String station, String type, String fuel, float amount, int capacity, float price) {
+        public FuelRow(String station, String type, String fuel, double amount, int capacity, float price) {
             this.station = station;
             this.type = type;
             this.fuel = fuel;
index 01562ac6bead073d9dd8f6446720fcf508d55ca7..478ef44c6c5062d328cb147701d370f12b58e69e 100644 (file)
@@ -43,9 +43,9 @@ public class StockTabController {
         }
 
         try {
-            float value = Float.parseFloat(txtAmount.getText().replace(",", "."));
+            double value = Double.parseDouble(txtAmount.getText().replace(",", "."));
             int capacity = getCapacity(station, type);
-            float current = station.getStored_amount(type);
+            double current = station.getStored_amount(type);
 
             if (rbAbsolute.isSelected()) {
                 if (value < 0 || value > capacity) {
@@ -57,7 +57,7 @@ public class StockTabController {
                 parentController.appendOutput("Stock of %s at %s set to %.2f L"
                         .formatted(type, parentController.getDisplayName(station), value));
             } else {
-                float updated = current + value;
+                double updated = current + value;
                 if (updated < 0 || updated > capacity) {
                     parentController.showError("Out of capacity bounds.");
                     return;
diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/UnderstaffedTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/UnderstaffedTabController.java
new file mode 100644 (file)
index 0000000..9c0be25
--- /dev/null
@@ -0,0 +1,47 @@
+package de.diejungsvondertanke.tankstelle.controllers;
+
+import java.io.IOException;
+
+import de.diejungsvondertanke.tankstelle.FuelStation;
+import de.diejungsvondertanke.tankstelle.Main;
+import javafx.fxml.FXML;
+import javafx.scene.control.TextField;
+
+public class UnderstaffedTabController {
+
+    @FXML
+    private TextField pin, staffCount;
+
+    private FuelStationUIController parentController;
+
+    // Called by parent after full initialization
+    public void setParentController(FuelStationUIController parent) {
+        this.parentController = parent;
+    }
+
+    @FXML
+    private void show() {
+        try {
+
+            if (Main.isPINCorrect(pin.getText())) {
+                try {
+                    if (Integer.parseInt(staffCount.getText()) <= Main.getTotalNumberOfEmployees()) {
+                        String out = "";
+                        for (FuelStation station : Main
+                                .getFuelStationListWhenUnderstaffed(Short.parseShort(staffCount.getText()))) {
+                            out += "\n - %s".formatted(parentController.getDisplayName(station));
+                        }
+                        parentController.appendOutput("Fuel stations that can be operated:" + out);
+                    } else {
+                        parentController.appendOutput("You don't have that many employees!");
+                    }
+                } catch (Exception e) {
+                }
+            } else {
+                parentController.appendOutput("invalid PIN");
+            }
+        } catch (IOException e) {
+        }
+    }
+
+}
index 0f728416f0c6d632fbde0d30bb422fbce17f60a8..5c470b95eaa0485e9eea72ad6227cf883fc377d1 100644 (file)
@@ -42,6 +42,9 @@
                 <Tab text="Overview" closable="false">
                     <BorderPane fx:id="overviewTabContainer" />
                 </Tab>
+                <Tab text="Understaffed" closable="false">
+                    <VBox fx:id="understaffedTabContainer" />
+                </Tab>
             </tabs>
         </TabPane>
     </center>
index f9771365bfbab1d2054e0c564b721d61f0ab9871..ac1c8d44630a67ec1fb0e83fc1f9cc34bc5527b3 100644 (file)
@@ -4,7 +4,7 @@
 <?import javafx.scene.layout.*?>
 
 <VBox xmlns:fx="http://javafx.com/fxml"
-      fx:controller="de.diejungsvondertanke.tankstelle.controllers.StockTabController"  spacing="10">
+      fx:controller="de.diejungsvondertanke.tankstelle.controllers.StockTabController" spacing="10">
       <padding>
             <Insets top="15" right="15" bottom="15" left="15" />
       </padding>
             <TextField fx:id="txtAmount" />
       </HBox>
 
-      <RadioButton fx:id="rbAbsolute" text="Set absolute" selected="true" />
-      <RadioButton fx:id="rbDelta" text="Change (+/-)" />
+      <fx:define>
+            <ToggleGroup fx:id="group" />
+      </fx:define>
+      <RadioButton fx:id="rbAbsolute" toggleGroup="$group" text="Set absolute" selected="true" />
+      <RadioButton fx:id="rbDelta" toggleGroup="$group" text="Change (+/-)" />
 
       <Button text="Change stock" onAction="#save" />
 </VBox>
\ No newline at end of file
diff --git a/src/main/resources/ui/UnderstaffedTab.fxml b/src/main/resources/ui/UnderstaffedTab.fxml
new file mode 100644 (file)
index 0000000..f1c01d7
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?import javafx.geometry.Insets?>
+<?import javafx.scene.control.*?>
+<?import javafx.scene.layout.*?>
+
+<VBox xmlns:fx="http://javafx.com/fxml"
+    fx:controller="de.diejungsvondertanke.tankstelle.controllers.UnderstaffedTabController"
+    spacing="10">
+
+    <padding>
+        <Insets top="15" right="15" bottom="15" left="15" />
+    </padding>
+
+    <Label
+        text="Show a list of fuel stations in the output window, which can be opened with the reduced staff count available" />
+
+    <Label text="PIN: " />
+    <HBox>
+        <TextField fx:id="pin" />
+    </HBox>
+
+    <Label text="no. of staff members available: " />
+    <HBox>
+        <TextField fx:id="staffCount" />
+    </HBox>
+
+    <Button text="Show stations" onAction="#show" />
+</VBox>
\ No newline at end of file