From: Robin Cheney Date: Sat, 22 Nov 2025 14:36:48 +0000 (+0100) Subject: finished UnderstaffedTab X-Git-Url: https://git.eternal.ddnss.de/?a=commitdiff_plain;h=842ed43799042743bb687cb96c7b69515c20956b;p=tankstelle.git finished UnderstaffedTab --- diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/Fuel.java b/src/main/java/de/diejungsvondertanke/tankstelle/Fuel.java index 2a13627..91a502e 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/Fuel.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/Fuel.java @@ -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; } diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java b/src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java index ac8f122..ea74a37 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java @@ -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(); diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/Main.java b/src/main/java/de/diejungsvondertanke/tankstelle/Main.java index ff433b2..6a91924 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/Main.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/Main.java @@ -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; diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/FuelStationUIController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/FuelStationUIController.java index f10ee65..4757243 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/FuelStationUIController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/FuelStationUIController.java @@ -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 diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/OverviewTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/OverviewTabController.java index eb25b14..1cde85e 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/OverviewTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/OverviewTabController.java @@ -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 colFuel; @FXML - private TableColumn colAmount; + private TableColumn colAmount; @FXML private TableColumn 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; diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java index 01562ac..478ef44 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java @@ -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 index 0000000..9c0be25 --- /dev/null +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/UnderstaffedTabController.java @@ -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) { + } + } + +} diff --git a/src/main/resources/ui/FuelStationUI.fxml b/src/main/resources/ui/FuelStationUI.fxml index 0f72841..5c470b9 100644 --- a/src/main/resources/ui/FuelStationUI.fxml +++ b/src/main/resources/ui/FuelStationUI.fxml @@ -42,6 +42,9 @@ + + + diff --git a/src/main/resources/ui/StockTab.fxml b/src/main/resources/ui/StockTab.fxml index f977136..ac1c8d4 100644 --- a/src/main/resources/ui/StockTab.fxml +++ b/src/main/resources/ui/StockTab.fxml @@ -4,7 +4,7 @@ + fx:controller="de.diejungsvondertanke.tankstelle.controllers.StockTabController" spacing="10"> @@ -13,8 +13,11 @@ - - + + + + +