]> Git Server - tankstelle.git/commitdiff
Changed fuelStations.toArray(new FuelStation[0])[0] to fuelStations.get(0)
authorRobin Cheney <cheneyr@eternal.ddnss.de>
Mon, 17 Nov 2025 16:57:33 +0000 (17:57 +0100)
committerRobin Cheney <cheneyr@eternal.ddnss.de>
Mon, 17 Nov 2025 16:57:33 +0000 (17:57 +0100)
src/main/java/de/diejungsvondertanke/tankstelle/Main.java

index 9a25493cdf9ed40b0ba7d7f21e2c81777ab324f6..106a4f6d23062bc298631988ba15fa5ccd0ed75d 100644 (file)
@@ -29,7 +29,6 @@ public class Main {
      */
     static ArrayList<FuelStation> fuelStations = new ArrayList<FuelStation>(Arrays.asList(initialFuelStations));
 
-
     /**
      * Main method
      * 
@@ -113,8 +112,8 @@ public class Main {
      * @author Nils Göbbert
      */
     public static FuelStation getHighestPrice(FuelType fuelType) throws NoSuchFuelTypeError {
-        float highestPrice = fuelStations.toArray(new FuelStation[0])[0].get_price(fuelType);
-        FuelStation highestStation = fuelStations.toArray(new FuelStation[0])[0];
+        float highestPrice = fuelStations.get(0).get_price(fuelType);
+        FuelStation highestStation = fuelStations.get(0);
         for (FuelStation fuelStation : fuelStations) {
             if (fuelStation.get_price(fuelType) > highestPrice) {
                 highestPrice = fuelStation.get_price(fuelType);
@@ -136,8 +135,8 @@ public class Main {
      * @author Nils Göbbert
      */
     public static FuelStation getHighestAccumulatedValue() throws NoSuchFuelTypeError {
-        float highestValue = fuelStations.toArray(new FuelStation[0])[0].get_cumulative_retail_price();
-        FuelStation highestStation = fuelStations.toArray(new FuelStation[0])[0];
+        float highestValue = fuelStations.get(0).get_cumulative_retail_price();
+        FuelStation highestStation = fuelStations.get(0);
         for (FuelStation fuelStation : fuelStations) {
             if (fuelStation.get_cumulative_retail_price() > highestValue) {
                 highestValue = fuelStation.get_cumulative_retail_price();
@@ -161,8 +160,8 @@ public class Main {
      * @author Nils Göbbert
      */
     public static FuelStation getHighestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError {
-        float highestAmount = fuelStations.toArray(new FuelStation[0])[0].getStored_amount(fuelType);
-        FuelStation highestStation = fuelStations.toArray(new FuelStation[0])[0];
+        float highestAmount = fuelStations.get(0).getStored_amount(fuelType);
+        FuelStation highestStation = fuelStations.get(0);
         for (FuelStation fuelStation : fuelStations) {
             if (fuelStation.getStored_amount(fuelType) > highestAmount) {
                 highestAmount = fuelStation.getStored_amount(fuelType);
@@ -186,8 +185,8 @@ public class Main {
      * @author Nils Göbbert
      */
     public static FuelStation getLowestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError {
-        float lowestAmount = fuelStations.toArray(new FuelStation[0])[0].getStored_amount(fuelType);
-        FuelStation lowestStation = fuelStations.toArray(new FuelStation[0])[0];
+        float lowestAmount = fuelStations.get(0).getStored_amount(fuelType);
+        FuelStation lowestStation = fuelStations.get(0);
         for (FuelStation fuelStation : fuelStations) {
             if (fuelStation.getStored_amount(fuelType) > lowestAmount) {
                 lowestAmount = fuelStation.getStored_amount(fuelType);
@@ -254,62 +253,66 @@ public class Main {
         return sum;
     }
 
-
     /**
      * Add new large fuel stations
+     * 
      * @param supermarket_company add the special attribut for large fuel stations
      * 
      * @author Leander Schnurrer
      */
-    public static void addNewFuelstation(String supermarket_company){
-        while(supermarket_company.isEmpty()){
-            // Show error in UI
+    public static void addNewFuelstation(String supermarket_company) {
+        while (supermarket_company.isEmpty()) {
+            // TODO: Show error in UI
         }
         fuelStations.add(new LargeFuelStation(supermarket_company));
     }
 
     /**
      * Add new medium fuel stations
+     * 
      * @param retail_space add the special attribut for medium fuel stations
      * 
      * @author Leander Schnurrer
      */
-    public static void addNewFuelstation(float retail_space){
-        while(retail_space <= 0) {
-            // Show error in UI
+    public static void addNewFuelstation(float retail_space) {
+        while (retail_space <= 0) {
+            // TODO: Show error in UI
         }
         fuelStations.add(new MediumFuelStation(retail_space));
     }
 
     /**
      * Add new small fuel stations
-     * @param number_of_vending_machines add the special attribut for small fuel stations
+     * 
+     * @param number_of_vending_machines add the special attribut for small fuel
+     *                                   stations
      * 
      * @author Leander Schnurrer
      */
-    public static void addNewFuelstation(short number_of_vending_machines){
-        while(number_of_vending_machines <= 0) {
-            // Show error in UI
+    public static void addNewFuelstation(short number_of_vending_machines) {
+        while (number_of_vending_machines <= 0) {
+            // TODO: Show error in UI
         }
         fuelStations.add(new SmallFuelStation(number_of_vending_machines));
     }
 
-
     /**
-     * Determine the total stock levels of selected petrol stations for a given type of fuel
+     * Determine the total stock levels of selected petrol stations for a given type
+     * of fuel
      * 
-     * @param fuelType select the fuel type
-     * @param FuelStations select the fuel stations 
+     * @param fuelType     select the fuel type
+     * @param FuelStations select the fuel stations
      * 
-     * @return the sum of stock levels of the specific fuel type from the selected fuel stations
+     * @return the sum of stock levels of the specific fuel type from the selected
+     *         fuel stations
      * 
      * @author Leander Schnurrer
      */
     public static float getTotalStockLevelOfFuel(FuelType fuelType, FuelStation[] FuelStations) {
         float sum = 0f;
-        for(FuelStation fuelStation : FuelStations){
-            for(Fuel fuel : fuelStation.fuels){
-                if(fuel.getFuelType() == fuelType){
+        for (FuelStation fuelStation : FuelStations) {
+            for (Fuel fuel : fuelStation.fuels) {
+                if (fuel.getFuelType() == fuelType) {
                     sum += fuel.getStored_amount();
                     break;
                 }
@@ -319,5 +322,4 @@ public class Main {
         return sum;
     }
 
-
 }
\ No newline at end of file