]> Git Server - tankstelle.git/commitdiff
Reworked some tabs
authorRobin Cheney <cheneyr@eternal.ddnss.de>
Mon, 1 Dec 2025 08:43:47 +0000 (09:43 +0100)
committerRobin Cheney <cheneyr@eternal.ddnss.de>
Mon, 1 Dec 2025 08:43:47 +0000 (09:43 +0100)
Some refactoring (moved the core .java files into .core package)
Introduced two new error classes (FuelTypeException, NoFuelTypeSelectedError)
Moved FuelRow record to separate file
Added some fail safe checks to give proper feedback

24 files changed:
src/main/java/de/diejungsvondertanke/tankstelle/FuelStationUI.java.old [deleted file]
src/main/java/de/diejungsvondertanke/tankstelle/controllers/FuelStationUIController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/NewStationTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/OverviewTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/PriceTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/ResultTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/SearchTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/UnderstaffedTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/core/Fuel.java [moved from src/main/java/de/diejungsvondertanke/tankstelle/Fuel.java with 98% similarity]
src/main/java/de/diejungsvondertanke/tankstelle/core/FuelStation.java [moved from src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java with 99% similarity]
src/main/java/de/diejungsvondertanke/tankstelle/core/FuelType.java [moved from src/main/java/de/diejungsvondertanke/tankstelle/FuelType.java with 85% similarity]
src/main/java/de/diejungsvondertanke/tankstelle/core/LargeFuelStation.java [moved from src/main/java/de/diejungsvondertanke/tankstelle/LargeFuelStation.java with 96% similarity]
src/main/java/de/diejungsvondertanke/tankstelle/core/Main.java [moved from src/main/java/de/diejungsvondertanke/tankstelle/Main.java with 94% similarity]
src/main/java/de/diejungsvondertanke/tankstelle/core/MediumFuelStation.java [moved from src/main/java/de/diejungsvondertanke/tankstelle/MediumFuelStation.java with 96% similarity]
src/main/java/de/diejungsvondertanke/tankstelle/core/Size.java [moved from src/main/java/de/diejungsvondertanke/tankstelle/Size.java with 91% similarity]
src/main/java/de/diejungsvondertanke/tankstelle/core/SmallFuelStation.java [moved from src/main/java/de/diejungsvondertanke/tankstelle/SmallFuelStation.java with 96% similarity]
src/main/java/de/diejungsvondertanke/tankstelle/error/FuelTypeException.java [new file with mode: 0644]
src/main/java/de/diejungsvondertanke/tankstelle/error/NoFuelTypeSelectedError.java [new file with mode: 0644]
src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java
src/main/java/de/diejungsvondertanke/tankstelle/ui/FuelRow.java [new file with mode: 0644]
src/main/java/module-info.java
src/main/resources/ui/FuelStationUI.fxml
src/main/resources/ui/UnderstaffedTab.fxml

diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/FuelStationUI.java.old b/src/main/java/de/diejungsvondertanke/tankstelle/FuelStationUI.java.old
deleted file mode 100644 (file)
index 54c1f26..0000000
+++ /dev/null
@@ -1,593 +0,0 @@
-package de.diejungsvondertanke.tankstelle;
-
-import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
-
-import javax.swing.*;
-import javax.swing.table.DefaultTableModel;
-import java.awt.*;
-import java.util.List;
-
-/**
- * GUI for fuel stations
- *
- * @author Sergej Pavlenko
- */
-public class FuelStationUI extends JFrame {
-
-    private JComboBox<String> comboFuelStations;
-    private JComboBox<FuelType> comboFuelTypes;
-    private JTextArea outputArea;
-    private JPanel contentPane = new JPanel();
-    private JList<String> listFuelStations;
-    private JTable tableFuelTypesPerStation;
-    private javax.swing.table.DefaultTableModel fuelTableModel;
-
-    public FuelStationUI() {
-        setContentPane(contentPane);
-        setTitle("Fuel Station Management System");
-        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-        setSize(800, 600);
-        setLocationRelativeTo(null);
-
-        initComponents();
-    }
-
-    /**
-     * Layout for GUI
-     *
-     * @author Sergej Pavlenko
-     */
-    private void initComponents() {
-        setLayout(new BorderLayout());
-
-        JPanel selectionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
-
-        comboFuelStations = new JComboBox<>(buildStationNames());
-        comboFuelTypes = new JComboBox<>(FuelType.values());
-
-        listFuelStations = new JList<>();
-        listFuelStations.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
-
-        refreshStationNames();
-
-        selectionPanel.add(new JLabel("Fuel station:"));
-        selectionPanel.add(comboFuelStations);
-        selectionPanel.add(new JLabel("Fuel type:"));
-        selectionPanel.add(comboFuelTypes);
-
-        add(selectionPanel, BorderLayout.NORTH);
-
-        JTabbedPane tabbedPane = new JTabbedPane();
-        tabbedPane.addTab("Result", createResultPanel());
-        tabbedPane.addTab("Change price", createPricePanel());
-        tabbedPane.addTab("Change stock", createStockPanel());
-        tabbedPane.addTab("Search", createSearchPanel());
-        tabbedPane.addTab("New fuel station", createNewFuelStationPanel());
-        tabbedPane.addTab("Overview", createOverviewPanel());
-
-        add(tabbedPane, BorderLayout.CENTER);
-
-        outputArea = new JTextArea();
-        outputArea.setEditable(false);
-        outputArea.setLineWrap(true);
-        outputArea.setWrapStyleWord(true);
-        JScrollPane scrollPane = new JScrollPane(outputArea);
-        scrollPane.setPreferredSize(new Dimension(800, 150));
-        add(scrollPane, BorderLayout.SOUTH);
-    }
-
-    /**
-     * Creates names for the fuel stations
-     *
-     * @return fuel station names
-     *
-     * @author Sergej Pavlenko
-     */
-    private String[] buildStationNames() {
-        List<FuelStation> stations = Main.fuelStations;
-        String[] names = new String[stations.size()];
-        for (int i = 0; i < stations.size(); i++) {
-            FuelStation fs = stations.get(i);
-            String typeName = fs.getClass().getSimpleName();
-            names[i] = "Station " + (i + 1) + " (" + typeName + ")";
-        }
-        return names;
-    }
-
-    /**
-     * Getter method
-     *
-     * @return selected fuel station
-     *
-     * @author Sergej Pavlenko
-     */
-    private FuelStation getSelectedStation() {
-        int idx = comboFuelStations.getSelectedIndex();
-        if (idx < 0 || idx >= Main.fuelStations.size()) {
-            return null;
-        }
-        return Main.fuelStations.get(idx);
-    }
-
-    /**
-     * Create Panel for results of arithmetic operations
-     *
-     * @return result panel
-     *
-     * @author Sergej Pavlenko
-     */
-    private JPanel createResultPanel() {
-        JPanel panel = new JPanel(new BorderLayout());
-
-        JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 5, 5));
-
-        JButton btnTotalPrice = new JButton("Total selling value of all available fuel types");
-        btnTotalPrice.addActionListener(e -> {
-            float sum = 0f;
-            for (FuelStation station : Main.fuelStations) {
-                sum += station.get_cumulative_retail_price();
-            }
-            appendOutput(String.format(
-                    "Total selling value of all available fuel types: %.2f €", sum));
-        });
-
-        JButton btnHighestPrice = new JButton("Fuel station with highest price (chosen fuel type)");
-        btnHighestPrice.addActionListener(e -> {
-            FuelType type = (FuelType) comboFuelTypes.getSelectedItem();
-            try {
-                FuelStation fs = Main.getHighestPrice(type);
-                appendOutput("Fuel station with highest price for " + type + ": "
-                        + getDisplayName(fs));
-            } catch (NoSuchFuelTypeError ex) {
-                showError("No fitting fuel station with chosen fuel type " + type + " found.");
-            }
-        });
-
-        JButton btnHighestTotalValue = new JButton("Fuel station with highest total value of all available fuel types");
-        btnHighestTotalValue.addActionListener(e -> {
-            try {
-                FuelStation fs = Main.getHighestAccumulatedValue();
-                appendOutput("Fuel station with highest total value of all available fuel types: "
-                        + getDisplayName(fs));
-            } catch (NoSuchFuelTypeError ex) {
-                showError("Error when calculating highest total value.");
-            }
-        });
-
-        JButton btnStock = new JButton("Highest / lowest stock (chosen fuel type)");
-        btnStock.addActionListener(e -> {
-            FuelType type = (FuelType) comboFuelTypes.getSelectedItem();
-            try {
-                FuelStation max = Main.getHighestStoredAmount(type);
-                FuelStation min = Main.getLowestStoredAmount(type);
-                appendOutput("For fuel type " + type + ":\n" +
-                        "  Highest stock: " + getDisplayName(max) + "\n" +
-                        "  Lowest stock: " + getDisplayName(min));
-            } catch (NoSuchFuelTypeError ex) {
-                showError("No fitting fuel station with fuel type " + type + " found.");
-            }
-        });
-
-        JButton btnTotalStock = new JButton("Total stock (chosen fuel station, chosen fuel type)");
-        btnTotalStock.addActionListener(e -> {
-            FuelType type = (FuelType) comboFuelTypes.getSelectedItem();
-            int[] indices = listFuelStations.getSelectedIndices();
-
-            if (indices.length == 0) {
-                showError("Please select at least one fuel station.");
-                return;
-            }
-
-            FuelStation[] selectedStations = new FuelStation[indices.length];
-            for (int i = 0; i < indices.length; i++) {
-                selectedStations[i] = Main.fuelStations.get(indices[i]);
-            }
-
-            float total = Main.getTotalStockLevelOfFuel(type, selectedStations);
-            appendOutput(String.format("Total stock of %s across %d chosen fuel stations: %.2f L", type, indices.length,
-                    total));
-        });
-
-        buttonPanel.add(btnTotalPrice);
-        buttonPanel.add(btnHighestPrice);
-        buttonPanel.add(btnHighestTotalValue);
-        buttonPanel.add(btnStock);
-        buttonPanel.add(btnTotalStock);
-
-        JScrollPane listScroller = new JScrollPane(listFuelStations);
-        listScroller.setPreferredSize(new Dimension(250, 0));
-
-        JPanel listPanel = new JPanel(new BorderLayout());
-        listPanel.add(new JLabel("Fuel station selection (multiple possible):"), BorderLayout.NORTH);
-        listPanel.add(listFuelStations, BorderLayout.CENTER);
-
-        panel.add(buttonPanel, BorderLayout.CENTER);
-        panel.add(listScroller, BorderLayout.EAST);
-        panel.add(listPanel, BorderLayout.EAST);
-
-        return panel;
-    }
-
-    /**
-     * Create Panel for price changing
-     *
-     * @return price changing Panel
-     *
-     * @author Sergej Pavlenko
-     */
-    private JPanel createPricePanel() {
-        JPanel panel = new JPanel(new GridBagLayout());
-        GridBagConstraints gbc = new GridBagConstraints();
-        gbc.insets = new Insets(5, 5, 5, 5);
-        gbc.fill = GridBagConstraints.HORIZONTAL;
-
-        JLabel lblPrice = new JLabel("New price per litre (€):");
-        JTextField txtPrice = new JTextField(10);
-        JButton btnSave = new JButton("Change price");
-
-        btnSave.addActionListener(e -> {
-            FuelStation station = getSelectedStation();
-            FuelType type = (FuelType) comboFuelTypes.getSelectedItem();
-            if (station == null) {
-                showError("No fuel station chosen.");
-                return;
-            }
-            try {
-                float newPrice = Float.parseFloat(txtPrice.getText().replace(",", "."));
-                station.set_price(type, newPrice);
-                appendOutput(String.format(
-                        "Price changed of %s at %s to %.3f €/L.",
-                        type, getDisplayName(station), newPrice));
-                txtPrice.setText("");
-            } catch (NumberFormatException ex) {
-                showError("Please enter a valid number for the price.");
-            } catch (NoSuchFuelTypeError ex) {
-                showError("This fuel station does not offer the fuel type " + type);
-            }
-        });
-
-        gbc.gridx = 0;
-        gbc.gridy = 0;
-        panel.add(lblPrice, gbc);
-        gbc.gridx = 1;
-        panel.add(txtPrice, gbc);
-
-        gbc.gridx = 0;
-        gbc.gridy = 1;
-        gbc.gridwidth = 2;
-        panel.add(btnSave, gbc);
-
-        return panel;
-    }
-
-    /**
-     * Create Panel to change stock
-     *
-     * @author Sergej Pavlenko
-     */
-    private JPanel createStockPanel() {
-        JPanel panel = new JPanel(new GridBagLayout());
-        GridBagConstraints gbc = new GridBagConstraints();
-        gbc.insets = new Insets(5, 5, 5, 5);
-        gbc.fill = GridBagConstraints.HORIZONTAL;
-
-        JLabel lblAmount = new JLabel("Amount (litre):");
-        JTextField txtAmount = new JTextField(10);
-        JRadioButton rbAbsolute = new JRadioButton("Set absolute amount", true);
-        JRadioButton rbDelta = new JRadioButton("Change amount (+/-)");
-        ButtonGroup group = new ButtonGroup();
-        group.add(rbAbsolute);
-        group.add(rbDelta);
-
-        JButton btnSave = new JButton("Change stock");
-
-        btnSave.addActionListener(e -> {
-            FuelStation station = getSelectedStation();
-            FuelType type = (FuelType) comboFuelTypes.getSelectedItem();
-            if (station == null) {
-                showError("No fuel station chosen.");
-                return;
-            }
-            try {
-                float value = Float.parseFloat(txtAmount.getText().replace(",", "."));
-                int capacity = getCapacity(station, type);
-                float current = station.getStored_amount(type);
-
-                if (rbAbsolute.isSelected()) {
-                    if (value < 0) {
-                        showError("Please enter a positive number");
-                        return;
-                    }
-                    if (value > capacity) {
-                        showError("Maximum capacity of " + capacity + " L is being crossed.");
-                        return;
-                    }
-                    station.set_stored_amount(value, type);
-                    appendOutput(String.format(
-                            "Changed stock of %s at %s to %.2f litre.",
-                            type, getDisplayName(station), value));
-                    txtAmount.setText("");
-                } else {
-                    float updated = current + value;
-                    if (updated < 0) {
-                        showError("The amount of fuel may not be negative.");
-                        return;
-                    }
-                    if (updated > capacity) {
-                        showError("Maximum capacity of " + capacity + " L is being crossed.");
-                        return;
-                    }
-
-                    station.add_stored_amount(value, type);
-                    appendOutput(String.format(
-                            "Stock changed of %s at %s by %.2f litre.",
-                            type, getDisplayName(station), value));
-                    txtAmount.setText("");
-                }
-            } catch (NumberFormatException ex) {
-                showError("Please enter a valid number for the amount.");
-            } catch (ArithmeticException ex) {
-                showError("Error: " + ex.getMessage());
-            } catch (NoSuchFuelTypeError ex) {
-                showError("This fuel station does not offer the fuel type " + type);
-            }
-        });
-
-        int y = 0;
-        gbc.gridx = 0;
-        gbc.gridy = y;
-        panel.add(lblAmount, gbc);
-        gbc.gridx = 1;
-        panel.add(txtAmount, gbc);
-
-        y++;
-        gbc.gridx = 0;
-        gbc.gridy = y;
-        gbc.gridwidth = 2;
-        panel.add(rbAbsolute, gbc);
-
-        y++;
-        gbc.gridy = y;
-        panel.add(rbDelta, gbc);
-
-        y++;
-        gbc.gridy = y;
-        panel.add(btnSave, gbc);
-
-        return panel;
-    }
-
-    private int getCapacity(FuelStation station, FuelType type) throws NoSuchFuelTypeError {
-        for (Fuel f : station.fuels) {
-            if (f.FUEL_TYPE == type) {
-                return f.CAPACITY;
-            }
-        }
-        throw new NoSuchFuelTypeError("This fuel station does not offer the fuel type " + type);
-    }
-
-    /**
-     * Create Panel for searching for a fuel station with a specific fuel type
-     *
-     * @author Sergej Pavlenko
-     */
-    private JPanel createSearchPanel() {
-        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
-
-        JButton btnListFuelStations = new JButton("Show fuel stations with chosen fuel type");
-        btnListFuelStations.addActionListener(e -> {
-            FuelType type = (FuelType) comboFuelTypes.getSelectedItem();
-            StringBuilder sb = new StringBuilder();
-            sb.append("Fuel station with fuel type ").append(type).append(":\n");
-            for (FuelStation station : Main.fuelStations) {
-                try {
-                    station.getStored_amount(type);
-                    sb.append(" - ").append(getDisplayName(station)).append("\n");
-                } catch (NoSuchFuelTypeError ex) {
-                }
-            }
-            appendOutput(sb.toString());
-        });
-
-        panel.add(btnListFuelStations);
-        return panel;
-    }
-
-    /**
-     * Create Panel for making new fuel stations
-     *
-     * @author Sergej Pavlenko
-     */
-    private JPanel createNewFuelStationPanel() {
-        JPanel panel = new JPanel(new GridBagLayout());
-        GridBagConstraints gbc = new GridBagConstraints();
-        gbc.insets = new Insets(5, 5, 5, 5);
-        gbc.fill = GridBagConstraints.HORIZONTAL;
-        gbc.anchor = GridBagConstraints.WEST;
-
-        JRadioButton rbSmall = new JRadioButton("Small fuel station", true);
-        JRadioButton rbMedium = new JRadioButton("Medium fuel station", true);
-        JRadioButton rbLarge = new JRadioButton("Large fuel station", true);
-
-        ButtonGroup buttonGroup = new ButtonGroup();
-        buttonGroup.add(rbSmall);
-        buttonGroup.add(rbMedium);
-        buttonGroup.add(rbLarge);
-
-        JLabel lblAtrributes = new JLabel("Special attribute:");
-        JTextField txtAtrributes = new JTextField(15);
-        JLabel lblHint = new JLabel("Small: amount of vending machines, Medium: m^2, Large: supermarket-company");
-
-        JButton btnAdd = new JButton("Add fuel station");
-        btnAdd.addActionListener(e -> {
-            try {
-                if (rbSmall.isSelected()) {
-                    short vendingMachines = Short.parseShort(txtAtrributes.getText().trim());
-                    Main.addNewFuelStation(vendingMachines);
-                    appendOutput("Fuel station with " + vendingMachines + " vending machines has been added.");
-                } else if (rbMedium.isSelected()) {
-                    float retailSpace = Float.parseFloat(txtAtrributes.getText().replace(",", ".").trim());
-                    Main.addNewFuelStation(retailSpace);
-                    appendOutput("Fuel station with " + retailSpace + " m^2 retail space has been added.");
-                } else if (rbLarge.isSelected()) {
-                    String supermarketCompany = txtAtrributes.getText().trim();
-                    Main.addNewFuelStation(supermarketCompany);
-                    appendOutput("Fuel station with supermarket-company" + supermarketCompany + " has been added.");
-                }
-                refreshStationNames();
-                txtAtrributes.setText("");
-            } catch (NumberFormatException ex) {
-                showError("Please enter a valid number (for small / medium).");
-            } catch (IllegalArgumentException ex) {
-                showError(ex.getMessage());
-            }
-        });
-
-        int y = 0;
-        gbc.gridx = 0;
-        gbc.gridy = y;
-        gbc.gridwidth = 3;
-        panel.add(new JLabel("Type of new fuel station:"), gbc);
-
-        y++;
-        gbc.gridy = y;
-        gbc.gridwidth = 1;
-        panel.add(rbSmall, gbc);
-        gbc.gridx = 1;
-        panel.add(rbMedium, gbc);
-        gbc.gridx = 2;
-        panel.add(rbLarge, gbc);
-
-        y++;
-        gbc.gridx = 0;
-        gbc.gridy = y;
-        panel.add(lblAtrributes, gbc);
-        gbc.gridx = 1;
-        gbc.gridwidth = 2;
-        panel.add(txtAtrributes, gbc);
-
-        y++;
-        gbc.gridx = 0;
-        gbc.gridy = y;
-        gbc.gridwidth = 3;
-        panel.add(lblHint, gbc);
-
-        y++;
-        gbc.gridy = y;
-        panel.add(btnAdd, gbc);
-
-        return panel;
-    }
-
-    /**
-     * Create Panel for overview of fuel stations
-     *
-     * @return overview Panel
-     *
-     * @author Sergej Pavlenko
-     */
-    private JPanel createOverviewPanel() {
-        JPanel panel = new JPanel(new BorderLayout());
-
-        fuelTableModel = new DefaultTableModel(
-                new Object[] { "Fuel station", "Station type", "Fuel", "Amount (L)", "Capacity (L)", "Price (€/L)" },
-                0) {
-            @Override
-            public boolean isCellEditable(int row, int column) {
-                return false;
-            }
-        };
-
-        tableFuelTypesPerStation = new JTable(fuelTableModel);
-
-        JScrollPane scrollPane = new JScrollPane(tableFuelTypesPerStation);
-
-        JButton btnRefresh = new JButton("Refresh");
-        btnRefresh.addActionListener(e -> refreshFuelTable());
-
-        JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
-        topPanel.add(new JLabel("Overview of all fuels per fuel station"));
-        topPanel.add(btnRefresh);
-
-        panel.add(topPanel, BorderLayout.NORTH);
-        panel.add(scrollPane, BorderLayout.CENTER);
-
-        refreshFuelTable();
-
-        return panel;
-    }
-
-    /**
-     * Updates the selection of fuel stations for ComboBox and List
-     *
-     * @author Sergej Pavlenko
-     */
-    private void refreshStationNames() {
-        String[] names = buildStationNames();
-
-        comboFuelStations.setModel(new DefaultComboBoxModel<>(names));
-
-        listFuelStations.setListData(names);
-    }
-
-    /**
-     * Updates table to keep up with changes
-     *
-     * @author Sergej Pavlenko
-     */
-    private void refreshFuelTable() {
-        if (fuelTableModel == null) {
-            return;
-        }
-
-        fuelTableModel.setRowCount(0);
-
-        for (FuelStation station : Main.fuelStations) {
-            String stationName = getDisplayName(station);
-            String stationType = station.getClass().getSimpleName();
-
-            for (Fuel fuel : station.fuels) {
-                Object[] row = new Object[] {
-                        stationName,
-                        stationType,
-                        fuel.FUEL_TYPE,
-                        fuel.getStored_amount(),
-                        fuel.CAPACITY,
-                        fuel.getPrice()
-                };
-                fuelTableModel.addRow(row);
-            }
-        }
-    }
-
-    private String getDisplayName(FuelStation station) {
-        int index = Main.fuelStations.indexOf(station);
-        if (index >= 0 && index < comboFuelStations.getItemCount()) {
-            return comboFuelStations.getItemAt(index);
-        }
-        return station.getClass().getSimpleName();
-    }
-
-    /**
-     * Creates a text output area
-     *
-     * @param text text output area
-     *
-     * @author Sergej Pavlenko
-     */
-    private void appendOutput(String text) {
-        outputArea.append(text + "\n\n");
-        outputArea.setCaretPosition(outputArea.getDocument().getLength());
-    }
-
-    /**
-     * Creates an error message
-     *
-     * @param message error message
-     *
-     * @author Sergej Pavlenko
-     */
-    private void showError(String message) {
-        JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
-    }
-}
index 6be6532c5740b2e943e49315b369cc616ea532d3..64c8fde9eb1a03f5f971ccf14a6d5c18eb9a1a2e 100644 (file)
@@ -3,7 +3,9 @@ package de.diejungsvondertanke.tankstelle.controllers;
 import java.io.IOException;
 import java.util.function.Consumer;
 
-import de.diejungsvondertanke.tankstelle.*;
+import de.diejungsvondertanke.tankstelle.core.FuelStation;
+import de.diejungsvondertanke.tankstelle.core.FuelType;
+import de.diejungsvondertanke.tankstelle.core.Main;
 import javafx.fxml.FXML;
 import javafx.fxml.FXMLLoader;
 import javafx.scene.Parent;
@@ -71,11 +73,14 @@ public class FuelStationUIController {
      * If not done correctly, using the controller in the subtabs WILL FAIL.
      * 
      * USING THE CONTROLLER OBJECT INSIDE THE {@code initialize()} FUNCTION OF THE
-     * SUBTABS IS NOT PERMITTED AND WILL ALWAYS BE {@code null} DUE TO TIMING
+     * SUBTABS WILL NOT WORK AND WILL ALWAYS BE {@code null} DUE TO TIMING ISSUES
      */
     @FXML
     public void initialize() {
-        // Load all tabs manually and keep controllers
+        /*
+         * Load all tabs manually and keep controllers
+         * If anyone asks, yes, this is necessary
+         */
         comboFuelTypes.getItems().setAll(FuelType.values());
         try {
 
@@ -114,21 +119,21 @@ public class FuelStationUIController {
                     });
         } catch (Exception e) {
             e.printStackTrace();
-            // TODO: handle exception
         }
+        // refresh every display
         refreshStationNames();
     }
 
     /**
      * Generic tab loader helper
      * 
-     * @param <T>                I have no idea what this does other than generalise
-     *                           the type for the consumer
+     * @param <T>                Controller class
      * @param fxmlPath           Path to the .fxml resource file
      * @param container          A container that inherits from {@link Parent}, for
      *                           example {@link GridPane}, {@link HBoc} or
      *                           {@link BorderPane}
-     * @param controllerConsumer A {@link Consumer} to
+     * @param controllerConsumer A {@link Consumer} to recieve the controller object
+     *                           from the loaded Tab
      * @throws IOException If loading the Tab failed because the .fxml file was not
      *                     found
      */
@@ -155,7 +160,7 @@ public class FuelStationUIController {
      * Get the {@link FuelStation} selected in the Drop-Down list at the top left of
      * the screen
      * 
-     * @return the selected fuel station or {@code null} if none selected
+     * @return The selected fuel station or {@code null} if none selected
      */
     public FuelStation getSelectedStation() {
         int idx = comboFuelStations.getSelectionModel().getSelectedIndex();
@@ -182,8 +187,8 @@ public class FuelStationUIController {
     /**
      * Create some display String for the fuel station lists in the UI
      * 
-     * @param fs a {@link FuelStation} object to get the display name for
-     * @return the display name string
+     * @param fs A {@link FuelStation} object to get the display name for
+     * @return The display name string
      */
     public String getDisplayName(FuelStation fs) {
         int index = Main.fuelStations.indexOf(fs);
index eae4e166c253679092b926b06b4092c345d547a2..3904e1b5308d150103c47647380ec3f6f895d69f 100644 (file)
@@ -1,6 +1,6 @@
 package de.diejungsvondertanke.tankstelle.controllers;
 
-import de.diejungsvondertanke.tankstelle.Main;
+import de.diejungsvondertanke.tankstelle.core.Main;
 import javafx.fxml.FXML;
 import javafx.scene.control.Label;
 import javafx.scene.control.RadioButton;
index 3b5d55cecd833e3be362868bdecc11779ef358b8..d78ccb6fa3ea7b67bbc31c947c9560c140da7bc0 100644 (file)
@@ -1,8 +1,10 @@
 package de.diejungsvondertanke.tankstelle.controllers;
 
-import de.diejungsvondertanke.tankstelle.Fuel;
-import de.diejungsvondertanke.tankstelle.FuelStation;
-import de.diejungsvondertanke.tankstelle.Main;
+import de.diejungsvondertanke.tankstelle.core.Fuel;
+import de.diejungsvondertanke.tankstelle.core.FuelStation;
+import de.diejungsvondertanke.tankstelle.core.Main;
+import de.diejungsvondertanke.tankstelle.ui.FuelRow;
+
 import javafx.beans.property.SimpleFloatProperty;
 import javafx.beans.property.SimpleIntegerProperty;
 import javafx.beans.property.SimpleStringProperty;
@@ -56,12 +58,12 @@ public class OverviewTabController {
      */
     @FXML
     public void initialize() {
-        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 SimpleDoubleProperty(data.getValue().getAmount()).asObject());
-        colCapacity.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getCapacity()).asObject());
-        colPrice.setCellValueFactory(data -> new SimpleFloatProperty(data.getValue().getPrice()).asObject());
+        colStation.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().station()));
+        colType.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().type()));
+        colFuel.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().fuel()));
+        colAmount.setCellValueFactory(data -> new SimpleDoubleProperty(data.getValue().amount()).asObject());
+        colCapacity.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().capacity()).asObject());
+        colPrice.setCellValueFactory(data -> new SimpleFloatProperty(data.getValue().price()).asObject());
     }
 
     /**
@@ -124,184 +126,4 @@ public class OverviewTabController {
         }
     }
 
-    /**
-     * Glorified record class for the data rows from the table.
-     */
-    public class FuelRow {
-
-        String station;
-        String type;
-        String fuel;
-        double amount;
-        int capacity;
-        float price;
-
-        /**
-         * Getter function
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @return the fuel station DISPLAY NAME, NOT THE STATION OBJECT
-         */
-        public String getStation() {
-            return station;
-        }
-
-        /**
-         * Set the new display name for the fuel station.
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @param station new display name
-         */
-        public void setStation(String station) {
-            this.station = station;
-        }
-
-        /**
-         * Getter function
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @return the fuel station type as a string
-         */
-        public String getType() {
-            return type;
-        }
-
-        /**
-         * set new fuel station type as a string
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @param type the new fuel station type
-         */
-        public void setType(String type) {
-            this.type = type;
-        }
-
-        /**
-         * Getter function
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @return the fuel type
-         */
-        public String getFuel() {
-            return fuel;
-        }
-
-        /**
-         * Set new fuel type as a string
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @param fuel new fuel type as a string
-         */
-        public void setFuel(String fuel) {
-            this.fuel = fuel;
-        }
-
-        /**
-         * Getter function
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @return the stored fuel amount
-         */
-        public double getAmount() {
-            return amount;
-        }
-
-        /**
-         * Set new stored amount
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @param amount new stored amount
-         */
-        public void setAmount(double amount) {
-            this.amount = amount;
-        }
-
-        /**
-         * Getter function
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @return maximum fuel capacity
-         */
-        public int getCapacity() {
-            return capacity;
-        }
-
-        /**
-         * Set new maximum fuel capacity
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @param capacity new maximum fuel capacity
-         */
-        public void setCapacity(int capacity) {
-            this.capacity = capacity;
-        }
-
-        /**
-         * Getter function
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @return fuel price per litre
-         */
-        public float getPrice() {
-            return price;
-        }
-
-        /**
-         * Set new price per litre
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @param price new price per litre
-         */
-        public void setPrice(float price) {
-            this.price = price;
-        }
-
-        /**
-         * constructs new FuelRows. This is used as a datatype in the "Overview" Tabs
-         * table
-         * 
-         * Note: THIS IS DISPLAY ONLY. CHANGES WILL NOT AFFECT THE
-         * REAL STATION OBJECTS
-         * 
-         * @param station  display name for the fuel station
-         * @param type     display name for the station type/size
-         * @param fuel     display name for the fuel type
-         * @param amount   stored amount of fuel
-         * @param capacity maximum capacity
-         * @param price    price per litre
-         */
-        public FuelRow(String station, String type, String fuel, double amount, int capacity, float price) {
-            this.station = station;
-            this.type = type;
-            this.fuel = fuel;
-            this.amount = amount;
-            this.capacity = capacity;
-            this.price = price;
-        }
-
-    }
-}
+}
\ No newline at end of file
index 27462f27f03b22f3f52229c800ba365c3ba9f8e3..c429999f2dec504d3fb88baf8c4f1e4f9d4dda8e 100644 (file)
@@ -1,7 +1,7 @@
 package de.diejungsvondertanke.tankstelle.controllers;
 
-import de.diejungsvondertanke.tankstelle.FuelStation;
-import de.diejungsvondertanke.tankstelle.FuelType;
+import de.diejungsvondertanke.tankstelle.core.FuelStation;
+import de.diejungsvondertanke.tankstelle.core.FuelType;
 import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
 import javafx.fxml.FXML;
 import javafx.scene.control.TextField;
@@ -38,7 +38,6 @@ public class PriceTabController {
     private void save() {
         FuelStation station = parentController.getSelectedStation();
         FuelType type = parentController.comboFuelTypes.getValue();
-
         if (station == null) {
             parentController.showError("Select a station.");
             return;
@@ -54,10 +53,10 @@ public class PriceTabController {
             txtPrice.clear();
             parentController.refreshStationNames();
 
-        } catch (NumberFormatException ex) {
+        } catch (NumberFormatException e) {
             parentController.showError("Invalid number.");
-        } catch (NoSuchFuelTypeError ex) {
-            parentController.showError("Fuel type not selected or unavailable.");
+        } catch (NoSuchFuelTypeError e) {
+            parentController.showError(e.getMessage());
         }
     }
 }
index d9c9ecbc81cb4e63d9dc0f4a28836fabb2b75889..97dd4fce21c02ac2b75ec56736d7d8a17cd1757a 100644 (file)
@@ -1,8 +1,10 @@
 package de.diejungsvondertanke.tankstelle.controllers;
 
-import de.diejungsvondertanke.tankstelle.FuelStation;
-import de.diejungsvondertanke.tankstelle.FuelType;
-import de.diejungsvondertanke.tankstelle.Main;
+import de.diejungsvondertanke.tankstelle.core.FuelStation;
+import de.diejungsvondertanke.tankstelle.core.FuelType;
+import de.diejungsvondertanke.tankstelle.core.Main;
+import de.diejungsvondertanke.tankstelle.error.FuelTypeException;
+import de.diejungsvondertanke.tankstelle.error.NoFuelTypeSelectedError;
 import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
 import javafx.fxml.FXML;
 import javafx.scene.control.ListView;
@@ -64,8 +66,8 @@ public class ResultTabController {
             FuelStation fs = Main.getHighestPrice(type);
             parentController.appendOutput("Highest price for %s: %s"
                     .formatted(type, parentController.getDisplayName(fs)));
-        } catch (NoSuchFuelTypeError ex) {
-            parentController.showError("Fuel type unavailable.");
+        } catch (FuelTypeException e) {
+            parentController.showError(e.getMessage());
         }
     }
 
@@ -77,13 +79,14 @@ public class ResultTabController {
         try {
             FuelStation fs = Main.getHighestAccumulatedValue();
             parentController.appendOutput("Highest total value: " + parentController.getDisplayName(fs));
-        } catch (NoSuchFuelTypeError ex) {
-            parentController.showError("Calculation error.");
+        } catch (NoSuchFuelTypeError e) {
+            parentController.showError(e.getMessage());
         }
     }
 
     /**
-     * 
+     * Calculate and display the lowest and highest stock for a selected
+     * {@link FuelType}
      */
     @FXML
     private void handleStock() {
@@ -96,8 +99,8 @@ public class ResultTabController {
                          - Highest: %s
                          - Lowest: %s
                     """.formatted(type, parentController.getDisplayName(max), parentController.getDisplayName(min)));
-        } catch (NoSuchFuelTypeError e) {
-            parentController.showError("Fuel type unavailable.");
+        } catch (FuelTypeException e) {
+            parentController.showError(e.getMessage());
         }
     }
 
@@ -115,7 +118,12 @@ public class ResultTabController {
                 .map(i -> Main.fuelStations.get(i))
                 .toArray(FuelStation[]::new);
 
-        float total = Main.getTotalStockLevelOfFuel(type, stations);
-        parentController.appendOutput("Total for %s: %.2f L".formatted(type, total));
+        float total;
+        try {
+            total = Main.getTotalStockLevelOfFuel(type, stations);
+            parentController.appendOutput("Total for %s: %.2f L".formatted(type, total));
+        } catch (NoFuelTypeSelectedError e) {
+            parentController.showError(e.getMessage());
+        }
     }
 }
index 1a9d121aebdb2970fc353597d2b7b3c60711e49c..bf97366bd97e403e443d77832f7c6aedfb8f193c 100644 (file)
@@ -1,8 +1,8 @@
 package de.diejungsvondertanke.tankstelle.controllers;
 
-import de.diejungsvondertanke.tankstelle.FuelStation;
-import de.diejungsvondertanke.tankstelle.FuelType;
-import de.diejungsvondertanke.tankstelle.Main;
+import de.diejungsvondertanke.tankstelle.core.FuelStation;
+import de.diejungsvondertanke.tankstelle.core.FuelType;
+import de.diejungsvondertanke.tankstelle.core.Main;
 import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
 import javafx.fxml.FXML;
 
index 778d6cdd3aab4187ebdd6e366080588ba68b5863..732077c10873cbb99ab844152b30524636e9d60d 100644 (file)
@@ -1,8 +1,8 @@
 package de.diejungsvondertanke.tankstelle.controllers;
 
-import de.diejungsvondertanke.tankstelle.Fuel;
-import de.diejungsvondertanke.tankstelle.FuelStation;
-import de.diejungsvondertanke.tankstelle.FuelType;
+import de.diejungsvondertanke.tankstelle.core.Fuel;
+import de.diejungsvondertanke.tankstelle.core.FuelStation;
+import de.diejungsvondertanke.tankstelle.core.FuelType;
 import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
 import javafx.fxml.FXML;
 import javafx.scene.control.RadioButton;
@@ -42,17 +42,17 @@ public class StockTabController {
             if (f.FUEL_TYPE == type)
                 return f.CAPACITY;
         }
-        throw new NoSuchFuelTypeError("Fuel type not available");
+        throw new NoSuchFuelTypeError("This fuel station does not have this type of fuel");
     }
 
     /**
-     * Save stock changes to the selected fuel type for the selected station
+     * Save stock changes to the selected fuel type for the selected station and
+     * give the user some feedback
      */
     @FXML
     private void save() {
         FuelStation station = parentController.getSelectedStation();
         FuelType type = parentController.comboFuelTypes.getValue();
-
         if (station == null) {
             parentController.showError("Select a station.");
             return;
@@ -65,7 +65,9 @@ public class StockTabController {
 
             if (rbAbsolute.isSelected()) {
                 if (value < 0 || value > capacity) {
-                    parentController.showError("Invalid amount.");
+                    parentController.showError(
+                            "Invalid amount. The stored amount cannot exceed the capacity (%dL) and must be greater or equal to 0"
+                                    .formatted(capacity));
                     return;
                 }
                 station.set_stored_amount(value, type);
@@ -75,7 +77,9 @@ public class StockTabController {
             } else {
                 double updated = current + value;
                 if (updated < 0 || updated > capacity) {
-                    parentController.showError("Out of capacity bounds.");
+                    parentController.showError(
+                            "Invalid amount. The stored amount cannot exceed the capacity (%dL) and must be greater or equal to 0"
+                                    .formatted(capacity));
                     return;
                 }
                 station.add_stored_amount(value, type);
@@ -86,8 +90,8 @@ public class StockTabController {
 
             txtAmount.clear();
 
-        } catch (Exception ex) {
-            parentController.showError(ex.getMessage());
+        } catch (Exception e) {
+            parentController.showError(e.getMessage());
         }
     }
 }
index 55e4a013f57ac40cc345c312735d47cf3b6f02f1..4488ba9a8ddecd1c1e884b1557ca3356c832e10f 100644 (file)
@@ -2,8 +2,8 @@ package de.diejungsvondertanke.tankstelle.controllers;
 
 import java.io.IOException;
 
-import de.diejungsvondertanke.tankstelle.FuelStation;
-import de.diejungsvondertanke.tankstelle.Main;
+import de.diejungsvondertanke.tankstelle.core.FuelStation;
+import de.diejungsvondertanke.tankstelle.core.Main;
 import javafx.fxml.FXML;
 import javafx.scene.control.TextField;
 
@@ -37,21 +37,23 @@ public class UnderstaffedTabController {
         try {
 
             if (Main.isPINCorrect(pin.getText())) {
-                try {
-                    if (Integer.parseInt(staffCount.getText()) <= Main.getTotalNumberOfEmployees()) {
+                int staffCountInt = Integer.parseInt(staffCount.getText());
+                if (staffCountInt <= Main.getTotalNumberOfEmployees()) {
+                    if (staffCountInt <= 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.showError("You can not have a negative employee count!");
+                } else {
+                    parentController.showError("You don't have that many employees!\nYou have %d."
+                            .formatted(Main.getTotalNumberOfEmployees()));
                 }
             } else {
-                parentController.appendOutput("invalid PIN");
+                parentController.showError("Invalid PIN");
             }
         } catch (IOException e) {
         }
similarity index 98%
rename from src/main/java/de/diejungsvondertanke/tankstelle/Fuel.java
rename to src/main/java/de/diejungsvondertanke/tankstelle/core/Fuel.java
index 91a502efda8907e5491c3a04169818a55b998d3d..4a25d1a18bad5155baa3198999abb63c6ca90bfa 100644 (file)
@@ -1,4 +1,4 @@
-package de.diejungsvondertanke.tankstelle;
+package de.diejungsvondertanke.tankstelle.core;
 
 /**
  * A fuel object. Contains fuel type, price per litre, stored fuel amount and
similarity index 99%
rename from src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java
rename to src/main/java/de/diejungsvondertanke/tankstelle/core/FuelStation.java
index ea74a37cd9f664367b142809fc8c52de131c140a..cc05f989f3443f7a14908d809b444f2a4d104711 100644 (file)
@@ -1,4 +1,4 @@
-package de.diejungsvondertanke.tankstelle;
+package de.diejungsvondertanke.tankstelle.core;
 
 import java.util.ArrayList;
 
similarity index 85%
rename from src/main/java/de/diejungsvondertanke/tankstelle/FuelType.java
rename to src/main/java/de/diejungsvondertanke/tankstelle/core/FuelType.java
index 09122842c36cabc86eac53c81bd1fe83387bef74..71c0016f02c7eddae937ae3fe3a463a8b6bea3b5 100644 (file)
@@ -1,4 +1,4 @@
-package de.diejungsvondertanke.tankstelle;
+package de.diejungsvondertanke.tankstelle.core;
 
 /**
  * Possible {@link Fuel fuel} types
@@ -41,4 +41,8 @@ public enum FuelType {
     public String toString() {
         return name;
     }
+
+    public static FuelType toEnum(String name) {
+        return FuelType.valueOf(name);
+    }
 }
similarity index 96%
rename from src/main/java/de/diejungsvondertanke/tankstelle/LargeFuelStation.java
rename to src/main/java/de/diejungsvondertanke/tankstelle/core/LargeFuelStation.java
index ed4ab66d23f2b35eb0ed50dd5d18f6655d737b4a..cea33aa4ca59d44866a21ce0c4361c6bd9b69167 100644 (file)
@@ -1,4 +1,4 @@
-package de.diejungsvondertanke.tankstelle;
+package de.diejungsvondertanke.tankstelle.core;
 
 /**
  * Large {@link FuelStation fuel station}
similarity index 94%
rename from src/main/java/de/diejungsvondertanke/tankstelle/Main.java
rename to src/main/java/de/diejungsvondertanke/tankstelle/core/Main.java
index a895b39a2c3642927802560be4bbd9e104123c34..75309303bf48e8b465841f20bed0ddc6cfa0fd54 100644 (file)
@@ -1,4 +1,4 @@
-package de.diejungsvondertanke.tankstelle;
+package de.diejungsvondertanke.tankstelle.core;
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -6,6 +6,7 @@ import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.Arrays;
 
+import de.diejungsvondertanke.tankstelle.error.NoFuelTypeSelectedError;
 import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
 import de.diejungsvondertanke.tankstelle.ui.JFX;
 
@@ -116,10 +117,13 @@ public class Main {
      * 
      * @author Nils Göbbert
      */
-    public static FuelStation getHighestPrice(FuelType fuelType) throws NoSuchFuelTypeError {
+    public static FuelStation getHighestPrice(FuelType fuelType) throws NoSuchFuelTypeError, NoFuelTypeSelectedError {
         FuelStation highestStation = null;
         float highestPrice = Float.NEGATIVE_INFINITY;
 
+        if (fuelType == null)
+            throw new NoFuelTypeSelectedError();
+
         for (FuelStation fuelStation : fuelStations) {
             try {
                 float price = fuelStation.get_price(fuelType);
@@ -128,7 +132,6 @@ public class Main {
                     highestStation = fuelStation;
                 }
             } catch (NoSuchFuelTypeError e) {
-
             }
         }
 
@@ -174,10 +177,12 @@ public class Main {
      * 
      * @author Nils Göbbert
      */
-    public static FuelStation getHighestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError {
+    public static FuelStation getHighestStoredAmount(FuelType fuelType)
+            throws NoSuchFuelTypeError, NoFuelTypeSelectedError {
         FuelStation highestStation = null;
         double highestAmount = Double.NEGATIVE_INFINITY;
-
+        if (fuelType == null)
+            throw new NoFuelTypeSelectedError();
         for (FuelStation fuelStation : fuelStations) {
             try {
                 double amount = fuelStation.getStored_amount(fuelType);
@@ -209,9 +214,12 @@ public class Main {
      * 
      * @author Nils Göbbert
      */
-    public static FuelStation getLowestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError {
+    public static FuelStation getLowestStoredAmount(FuelType fuelType)
+            throws NoSuchFuelTypeError, NoFuelTypeSelectedError {
         FuelStation lowestStation = null;
         double lowestAmount = Double.POSITIVE_INFINITY;
+        if (fuelType == null)
+            throw new NoFuelTypeSelectedError();
 
         for (FuelStation fuelStation : fuelStations) {
             try {
@@ -343,8 +351,11 @@ public class Main {
      * 
      * @author Leander Schnurrer
      */
-    public static float getTotalStockLevelOfFuel(FuelType fuelType, FuelStation[] fuelStations) {
+    public static float getTotalStockLevelOfFuel(FuelType fuelType, FuelStation[] fuelStations)
+            throws NoFuelTypeSelectedError {
         float sum = 0f;
+        if (fuelType == null)
+            throw new NoFuelTypeSelectedError();
         for (FuelStation fuelStation : fuelStations) {
             for (Fuel fuel : fuelStation.fuels) {
                 if (fuel.FUEL_TYPE == fuelType) {
similarity index 96%
rename from src/main/java/de/diejungsvondertanke/tankstelle/MediumFuelStation.java
rename to src/main/java/de/diejungsvondertanke/tankstelle/core/MediumFuelStation.java
index 2ce9cc4956082fab59cec8fd2fb3783132d60910..7a15b9f3cdf7fdf2e9b2186171f93d2a4543ceb3 100644 (file)
@@ -1,4 +1,4 @@
-package de.diejungsvondertanke.tankstelle;
+package de.diejungsvondertanke.tankstelle.core;
 
 /**
  * Medium {@link FuelStation fuel station}
similarity index 91%
rename from src/main/java/de/diejungsvondertanke/tankstelle/Size.java
rename to src/main/java/de/diejungsvondertanke/tankstelle/core/Size.java
index b4060810ad96753e20094466effc384363548a98..461dc111064684d9b124f89de5acf51fd3dad0c5 100644 (file)
@@ -1,4 +1,4 @@
-package de.diejungsvondertanke.tankstelle;
+package de.diejungsvondertanke.tankstelle.core;
 
 /**
  * The size of a {@link FuelStation fuel station}. Is more or less decorative,
similarity index 96%
rename from src/main/java/de/diejungsvondertanke/tankstelle/SmallFuelStation.java
rename to src/main/java/de/diejungsvondertanke/tankstelle/core/SmallFuelStation.java
index 3abce91c2dbb1dc5b720aa4153f71f60ec3a4871..e8002d647e3d9a11b4c4c0a54a40c5b89c811104 100644 (file)
@@ -1,4 +1,4 @@
-package de.diejungsvondertanke.tankstelle;
+package de.diejungsvondertanke.tankstelle.core;
 
 /**
  * Small {@link FuelStation fuel station}
diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/error/FuelTypeException.java b/src/main/java/de/diejungsvondertanke/tankstelle/error/FuelTypeException.java
new file mode 100644 (file)
index 0000000..22b6885
--- /dev/null
@@ -0,0 +1,21 @@
+package de.diejungsvondertanke.tankstelle.error;
+
+import de.diejungsvondertanke.tankstelle.core.FuelType;
+
+/**
+ * Generic {@link FuelType} error class
+ * 
+ * @author Robin Cheney
+ */
+public abstract class FuelTypeException extends Exception {
+    /**
+     * Throws a {@link NoFuelTypeSelectedError}
+     * 
+     * @param message Message to throw with this error
+     * 
+     * @author Robin Cheney
+     */
+    public FuelTypeException(String message) {
+        super(message);
+    }
+}
diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/error/NoFuelTypeSelectedError.java b/src/main/java/de/diejungsvondertanke/tankstelle/error/NoFuelTypeSelectedError.java
new file mode 100644 (file)
index 0000000..002befc
--- /dev/null
@@ -0,0 +1,29 @@
+package de.diejungsvondertanke.tankstelle.error;
+
+/**
+ * This Error is thrown on the attempt to get the selected fuel type whenever
+ * there is none selected
+ * 
+ * @author Robin Cheney
+ */
+public class NoFuelTypeSelectedError extends FuelTypeException {
+    /**
+     * Throws a {@link NoFuelTypeSelectedError}
+     * 
+     * @param message Message to throw with this error
+     * 
+     * @author Robin Cheney
+     */
+    public NoFuelTypeSelectedError(String message) {
+        super(message);
+    }
+
+    /**
+     * Throws a {@link NoFuelTypeSelectedError}
+     * 
+     * @author Robin Cheney
+     */
+    public NoFuelTypeSelectedError() {
+        super("No fuel type selected");
+    }
+}
index 8c8851e5f62e3f8c73913304f8c203f900339b35..935272c435a025f698170fb650ae5c21ae87d589 100644 (file)
@@ -6,7 +6,7 @@ package de.diejungsvondertanke.tankstelle.error;
  * 
  * @author Robin Cheney
  */
-public class NoSuchFuelTypeError extends Exception {
+public class NoSuchFuelTypeError extends FuelTypeException {
     /**
      * Throws a {@link NoSuchFuelTypeError}
      * 
@@ -24,6 +24,6 @@ public class NoSuchFuelTypeError extends Exception {
      * @author Robin Cheney
      */
     public NoSuchFuelTypeError() {
-        super();
+        super("This fuel station does not have this type of fuel");
     }
 }
diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/ui/FuelRow.java b/src/main/java/de/diejungsvondertanke/tankstelle/ui/FuelRow.java
new file mode 100644 (file)
index 0000000..8243111
--- /dev/null
@@ -0,0 +1,10 @@
+package de.diejungsvondertanke.tankstelle.ui;
+
+/**
+ * Glorified record class for the data rows from the table. This is only used
+ * for the table in the "Overview" tab in the ui
+ * 
+ * @author Robin Cheney
+ */
+public record FuelRow(String station, String type, String fuel, double amount, int capacity, float price) {
+}
\ No newline at end of file
index a5e6182f8541d7728526e08e3a1421cd6acab588..8eaeebf86a815091e092bf9b258d518e5250f194 100644 (file)
@@ -8,5 +8,5 @@ module tankstelle {
     opens de.diejungsvondertanke.tankstelle.controllers to javafx.fxml,
             javafx.graphics;
 
-    exports de.diejungsvondertanke.tankstelle;
+    exports de.diejungsvondertanke.tankstelle.core;
 }
index 5c470b95eaa0485e9eea72ad6227cf883fc377d1..d53b3e5b11c2e033c5f60363e7e16223f3b7aee7 100644 (file)
                 <Tab text="New fuel station" closable="false">
                     <VBox fx:id="newStationTabContainer" />
                 </Tab>
-                <Tab text="Overview" closable="false">
-                    <BorderPane fx:id="overviewTabContainer" />
-                </Tab>
                 <Tab text="Understaffed" closable="false">
                     <VBox fx:id="understaffedTabContainer" />
                 </Tab>
+                <Tab text="Overview" closable="false">
+                    <BorderPane fx:id="overviewTabContainer" />
+                </Tab>
             </tabs>
         </TabPane>
     </center>
index f1c01d7a32262cd8e7b064abff80ea60c5aa2c31..3f27bc911df67080aafd771f5767b74cc7689d6d 100644 (file)
@@ -19,7 +19,7 @@
         <TextField fx:id="pin" />
     </HBox>
 
-    <Label text="no. of staff members available: " />
+    <Label text="no. of employees available: " />
     <HBox>
         <TextField fx:id="staffCount" />
     </HBox>