]> Git Server - tankstelle.git/commitdiff
Added get_price method in FuelStation
authorRobin <cheneyr@eternal.ddnss.de>
Mon, 10 Nov 2025 10:11:07 +0000 (11:11 +0100)
committerRobin <cheneyr@eternal.ddnss.de>
Mon, 10 Nov 2025 10:11:07 +0000 (11:11 +0100)
src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java

index 00eb4565b0286bef9209b5828d859326c9df5c9f..31be9e68c64d469d7d79d88a5c38fad70d92673c 100644 (file)
@@ -70,4 +70,21 @@ abstract class FuelStation {
         throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type");
     }
 
+    /**
+     * Get the price for a specific type of fuel for this fuel station
+     * 
+     * @param fuel_type The {@link FuelType} to get
+     * @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 float get_price(FuelType fuel_type) throws NoSuchFuelTypeError {
+        for (Fuel i : fuels) {
+            if (i.FUEL_TYPE == fuel_type) {
+                return i.getPrice();
+            }
+        }
+        throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type");
+    }
+
 }