]> Git Server - tankstelle.git/commitdiff
Added set_price method in FuelStation
authorRobin <cheneyr@eternal.ddnss.de>
Mon, 10 Nov 2025 10:08:06 +0000 (11:08 +0100)
committerRobin <cheneyr@eternal.ddnss.de>
Mon, 10 Nov 2025 10:08:06 +0000 (11:08 +0100)
Added new exception: NoSuchFuelTypeError

src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java
src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java [new file with mode: 0644]

index 8e0916570a39f312a0329815b207c36560b26402..00eb4565b0286bef9209b5828d859326c9df5c9f 100644 (file)
@@ -1,5 +1,7 @@
 package de.diejungsvondertanke.tankstelle;
 
+import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
+
 /**
  * Abstract class.
  * All fuel station subtypes inherit from this class.
@@ -45,8 +47,27 @@ abstract class FuelStation {
         this.fuels = fuels;
     }
 
-    public void set_stored_amount (float stored_amount, FuelType type){
-        
+    public void set_stored_amount(float stored_amount, FuelType type) {
+
+    }
+
+    /**
+     * Set a new price for a specific type of fuel for this fuel station
+     * 
+     * @param fuel_type The {@link FuelType} to change
+     * @param price     The new price per litre
+     * @throws NoSuchFuelTypeError This Error is thrown on the attempt to choose a
+     *                             fuel type from a fuel station
+     *                             which the fuel station does not have
+     */
+    public void set_price(FuelType fuel_type, float price) throws NoSuchFuelTypeError {
+        for (Fuel i : fuels) {
+            if (i.FUEL_TYPE == fuel_type) {
+                i.setPrice(price);
+                return;
+            }
+        }
+        throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type");
     }
 
 }
diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java b/src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java
new file mode 100644 (file)
index 0000000..1ce5b47
--- /dev/null
@@ -0,0 +1,23 @@
+package de.diejungsvondertanke.tankstelle.error;
+
+/**
+ * This Error is thrown on the attempt to choose a fuel type from a fuel station
+ * which the fuel station does not have
+ */
+public class NoSuchFuelTypeError extends Exception {
+    /**
+     * Throws a {@link NoSuchFuelTypeError}
+     * 
+     * @param message Message to throw with this error
+     */
+    public NoSuchFuelTypeError(String message) {
+        super(message);
+    }
+
+    /**
+     * Throws a {@link NoSuchFuelTypeError}
+     */
+    public NoSuchFuelTypeError() {
+        super();
+    }
+}