]> Git Server - tankstelle.git/commitdiff
Highest Fuel pice method
authorNils Göbbert <adamantschild@gmail.com>
Tue, 11 Nov 2025 18:54:58 +0000 (19:54 +0100)
committerNils Göbbert <adamantschild@gmail.com>
Tue, 11 Nov 2025 18:54:58 +0000 (19:54 +0100)
src/main/java/de/diejungsvondertanke/tankstelle/Main.java

index 4732ded67eb33ad69727b37c6ac3d39633a26e01..53b3e4f4d4ad7f3871d1ecd62b1e88e397aad5b1 100644 (file)
@@ -2,6 +2,8 @@ package de.diejungsvondertanke.tankstelle;
 
 import java.util.ArrayList;
 
+import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
+
 /**
  * Main Class
  */
@@ -70,4 +72,23 @@ public class Main {
         }
         return result.toArray(new FuelStation[0]); // Change to LargeFuelStation if required
     }
+    /**
+     * Get the FuelStation with the highest price
+     * 
+     * 
+     * @param fuelType Select the type of fuel
+     * 
+     * @return a FuelStation (all of type {@link FuelStation})
+     */
+    public static FuelStation getHighestPrise (FuelType fuelType) throws NoSuchFuelTypeError {
+        float highestPrice = fuelStations[0].get_price(fuelType);
+        FuelStation HighestStation = fuelStations[0];
+        for (FuelStation fuelStation : fuelStations) {
+            if (fuelStation.get_price(fuelType) > highestPrice){
+                highestPrice = fuelStation.get_price(fuelType);
+                HighestStation = fuelStation;
+            }
+        }
+        return HighestStation;
+    }
 }
\ No newline at end of file