]> Git Server - tankstelle.git/commitdiff
Merge branch 'master' of https://repo.eternal.ddnss.de/git/tankstelle
authorRobin Cheney <cheneyr@eternal.ddnss.de>
Sun, 16 Nov 2025 09:02:24 +0000 (10:02 +0100)
committerRobin Cheney <cheneyr@eternal.ddnss.de>
Sun, 16 Nov 2025 09:02:24 +0000 (10:02 +0100)
1  2 
src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java
src/main/java/de/diejungsvondertanke/tankstelle/Main.java

index 3702c6e799d84e7d18ae1f6e53624dd833e31790,d1df8295053bdc7afb68fafbfa096d158a0a90cb..338203af3891f270655499da414c87584d67f91c
@@@ -150,37 -148,28 +150,54 @@@ abstract class FuelStation 
      }
  
      /**
 -     * Set a new number of employees for this fuel station
 +     * Sort the fuel stations by size in a descending order (largest stations first)
       * 
 -     * @param number_of_employees new number of employees for this fuel station
 +     * @param stations Array of {@link FuelStation}s
 +     * @return an ordered array of {@link FuelStation}s
       */
 -    public void setNumber_of_employees(byte number_of_employees) {
 -        this.number_of_employees = number_of_employees;
 +    public static FuelStation[] sort(FuelStation[] stations) {
 +        ArrayList<FuelStation> result = new ArrayList<>();
 +        ArrayList<FuelStation> large = new ArrayList<>();
 +        ArrayList<FuelStation> medium = new ArrayList<>();
 +        ArrayList<FuelStation> small = new ArrayList<>();
 +
 +        for (FuelStation station : stations) {
 +            switch (station.size) {
 +                case SMALL:
 +                    small.add(station);
 +                    break;
 +                case MEDIUM:
 +                    medium.add(station);
 +                    break;
 +                case LARGE:
 +                    large.add(station);
 +                    break;
 +                default:
 +                    System.out.println("Unknown FuelStation size for object: " + station.toString());
 +                    break;
 +            }
 +
 +        }
 +        result.addAll(large);
 +        result.addAll(medium);
 +        result.addAll(small);
 +        return result.toArray(new FuelStation[0]);
      }
 -     * Get the fuel amound for a specific type of fuel for this fuel station
+     /**
 -}
++     * Get the fuel amount 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 8ac4cdbdb574ddf645a008d593759398d053781d,d193465f1087be5bcf6e60f7e38ba2b792dbd78d..f26d80ac062eebbe4cbce0635baa98434aaa7402
@@@ -96,39 -93,61 +96,97 @@@ 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;
+     }
+       /**
+      * 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;
+     }
++
 +    /**
 +     * Check {@code pin} for the correct PIN number
 +     * 
 +     * @param pin the PIN to check
 +     * @return true, if the pin is correct, false otherwise
 +     * @throws IOException if the configured file pin.txt was not found
 +     */
 +    public static boolean isPINCorrect(String pin) throws IOException {
 +
 +        BufferedReader bfro = new BufferedReader(new InputStreamReader(Main.class.getResourceAsStream("/pin.txt")));
 +
 +        if (bfro.readLine().trim().equals(pin.trim()))
 +            return true;
 +        else
 +            return false;
 +    }
 +
 +    /**
 +     * This function will, for any number of employees, return an array of
 +     * {@link FuelStation}s that can be opened with the staff given
 +     * 
 +     * @param available_employees number of employees available
 +     * @return All fuel stations that can reasonably be opened today
 +     */
 +    public static FuelStation[] getFuelStationListWhenUnderstaffed(short available_employees) {
 +        ArrayList<FuelStation> result = new ArrayList<>();
 +        FuelStation[] fuelStationsLocalCopy = FuelStation.sort(fuelStations);
 +        for (FuelStation station : fuelStationsLocalCopy) {
 +            if (Math.floorDiv(available_employees, station.getNumber_of_employees()) >= 1) {
 +                available_employees -= station.getNumber_of_employees();
 +                result.add(station);
 +            }
 +        }
 +        return result.toArray(new FuelStation[0]);
 +    }
  }