]> Git Server - tankstelle.git/commitdiff
added function to get highest and lowest fuel
authorNils Göbbert <adamantschild@gmail.com>
Sat, 15 Nov 2025 15:46:21 +0000 (16:46 +0100)
committerNils Göbbert <adamantschild@gmail.com>
Sat, 15 Nov 2025 15:46:21 +0000 (16:46 +0100)
src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java
src/main/java/de/diejungsvondertanke/tankstelle/Main.java

index d73ee1082b5d019deefe5c3cbd49bc1e4fd7372f..d1df8295053bdc7afb68fafbfa096d158a0a90cb 100644 (file)
@@ -155,4 +155,21 @@ abstract class FuelStation {
     public void setNumber_of_employees(byte number_of_employees) {
         this.number_of_employees = number_of_employees;
     }
+
+    /**
+     * Get the fuel amound for a specific type of fuel for this fuel station
+     * 
+     * @param fuel_type The {@link FuelType 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 getStored_amount(FuelType fuel_type) throws NoSuchFuelTypeError {
+        for (Fuel i : fuels) {
+            if (i.FUEL_TYPE == fuel_type) {
+                return i.getStored_amount();
+            }
+        }
+        throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type");
+    }
 }
index e4125394e5ac033950a2d6cbe461671f85a89a6c..d193465f1087be5bcf6e60f7e38ba2b792dbd78d 100644 (file)
@@ -112,4 +112,42 @@ public class Main {
         }
         return highestStation;
     }
+      /**
+     * Get the FuelStation with the stored fuel
+     * 
+     * 
+     * @param fuelType Select the type of fuel
+     * 
+     * @return a FuelStation (all of type {@link FuelStation})
+     */
+    public static FuelStation getHighestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError{
+        float highestAmound = fuelStations[0].getStored_amount(fuelType);
+        FuelStation highestStation = fuelStations[0];
+        for (FuelStation fuelStation : fuelStations) {
+            if (fuelStation.getStored_amount(fuelType) > highestAmound) {
+                highestAmound = fuelStation.getStored_amount(fuelType);
+                highestStation = fuelStation;
+            }
+        }
+        return highestStation;
+    }
+      /**
+     * Get the FuelStation with the lowest fuel
+     * 
+     * 
+     * @param fuelType Select the type of fuel
+     * 
+     * @return a FuelStation (all of type {@link FuelStation})
+     */
+        public static FuelStation getLowerstStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError{
+        float LowestAmound = fuelStations[0].getStored_amount(fuelType);
+        FuelStation LowestStation = fuelStations[0];
+        for (FuelStation fuelStation : fuelStations) {
+            if (fuelStation.getStored_amount(fuelType) > LowestAmound) {
+                LowestAmound = fuelStation.getStored_amount(fuelType);
+                LowestStation = fuelStation;
+            }
+        }
+        return LowestStation;
+    }
 }
\ No newline at end of file