]> Git Server - tankstelle.git/commitdiff
added funktions to find specific Fuel stations
authorNils Göbbert <adamantschild@gmail.com>
Sat, 15 Nov 2025 15:44:05 +0000 (16:44 +0100)
committerNils Göbbert <adamantschild@gmail.com>
Sat, 15 Nov 2025 15:44:05 +0000 (16:44 +0100)
src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java
src/main/java/de/diejungsvondertanke/tankstelle/Main.java

index 8de2dd6428cac2f14cdddd9ba7595201e198bac4..d73ee1082b5d019deefe5c3cbd49bc1e4fd7372f 100644 (file)
@@ -130,8 +130,8 @@ abstract class FuelStation {
      * 
      * @return the income in €
      */
-    public double get_cumulative_retail_price() {
-        double result = 0;
+    public float get_cumulative_retail_price() {
+        float result = 0;
         for (Fuel i : fuels) {
             result += i.getPrice() * i.getStored_amount();
         }
index d028e5b1c98bc88486eec0fab35ea22993bd7939..e4125394e5ac033950a2d6cbe461671f85a89a6c 100644 (file)
@@ -92,4 +92,24 @@ public class Main {
         }
         return highestStation;
     }
+
+        /**
+     * 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 getHighestAccumulatedWorth() throws NoSuchFuelTypeError {
+        float highestWorth = fuelStations[0].get_cumulative_retail_price();
+        FuelStation highestStation = fuelStations[0];
+        for (FuelStation fuelStation : fuelStations) {
+            if (fuelStation.get_cumulative_retail_price() > highestWorth) {
+                highestWorth = fuelStation.get_cumulative_retail_price();
+                highestStation = fuelStation;
+            }
+        }
+        return highestStation;
+    }
 }
\ No newline at end of file