]> Git Server - tankstelle.git/commitdiff
Completed: Show fuel stations which have a specific value in their special attribute
authorRobin <cheneyr@eternal.ddnss.de>
Mon, 10 Nov 2025 11:04:37 +0000 (12:04 +0100)
committerRobin <cheneyr@eternal.ddnss.de>
Mon, 10 Nov 2025 11:04:37 +0000 (12:04 +0100)
Note: For the sake of simplicity, all three overloads return the same datatype FuelStation[]

src/main/java/de/diejungsvondertanke/tankstelle/LargeFuelStation.java
src/main/java/de/diejungsvondertanke/tankstelle/Main.java
src/main/java/de/diejungsvondertanke/tankstelle/MediumFuelStation.java
src/main/java/de/diejungsvondertanke/tankstelle/SmallFuelStation.java

index 43dc3522aa6e2df70cc19185ea9c158afe3dd423..43c8f94cc0e676bcd4bd3fd72ea6c11a10aa4386 100644 (file)
@@ -42,4 +42,13 @@ public class LargeFuelStation extends FuelStation {
         super(number_of_employees, Size.LARGE, fuels);
         this.supermarket_company = supermarket_company;
     }
+
+    /**
+     * Getter method
+     * 
+     * @return the name of the company running the integrated supermarket
+     */
+    public String getSupermarket_company() {
+        return supermarket_company;
+    }
 }
index a49fa88ae5d6751147be56fd81f026af7ef742dd..4732ded67eb33ad69727b37c6ac3d39633a26e01 100644 (file)
@@ -1,5 +1,7 @@
 package de.diejungsvondertanke.tankstelle;
 
+import java.util.ArrayList;
+
 /**
  * Main Class
  */
@@ -14,4 +16,58 @@ public class Main {
 
     public static void main(String[] args) {
     }
+
+    /**
+     * Get an array of fuel stations which have a number of vending machines
+     * that is equal to {@code number_of_vending_machines}
+     * 
+     * @param number_of_vending_machines Select all fuel stations with this number
+     *                                   of vending machines
+     * @return an array of fuel stations (all of type {@link SmallFuelStation})
+     */
+    public static FuelStation[] getFuelStations(short number_of_vending_machines) {
+        ArrayList<FuelStation> result = new ArrayList<FuelStation>();
+        for (FuelStation fuelStation : fuelStations) {
+            if (fuelStation instanceof SmallFuelStation
+                    && ((SmallFuelStation) fuelStation).getNumber_of_vending_machines() == number_of_vending_machines)
+                result.add(fuelStation);
+        }
+        return result.toArray(new FuelStation[0]); // Change to SmallFuelStation if required
+    }
+
+    /**
+     * Get an array of fuel stations which have an amount of square
+     * metres of retail space that is equal to {@code retail_space}
+     * 
+     * @param retail_space Select all fuel stations with this amount of square
+     *                     metres of retail space
+     * @return an array of fuel stations (all of type {@link MediumFuelStation})
+     */
+    public static FuelStation[] getFuelStations(float retail_space) {
+        ArrayList<FuelStation> result = new ArrayList<FuelStation>();
+        for (FuelStation fuelStation : fuelStations) {
+            if (fuelStation instanceof MediumFuelStation
+                    && ((MediumFuelStation) fuelStation).getRetail_space() == retail_space)
+                result.add(fuelStation);
+        }
+        return result.toArray(new FuelStation[0]); // Change to MediumFuelStation if required
+    }
+
+    /**
+     * Get an array of fuel stations whose integrated supermarket is run by
+     * {@code retail_space}
+     * 
+     * @param supermarket_company Select all fuel stations with this company running
+     *                            the integrated supermarket
+     * @return an array of fuel stations (all of type {@link LargeFuelStation})
+     */
+    public static FuelStation[] getFuelStations(String supermarket_company) {
+        ArrayList<FuelStation> result = new ArrayList<FuelStation>();
+        for (FuelStation fuelStation : fuelStations) {
+            if (fuelStation instanceof LargeFuelStation
+                    && ((LargeFuelStation) fuelStation).getSupermarket_company().equals(supermarket_company))
+                result.add(fuelStation);
+        }
+        return result.toArray(new FuelStation[0]); // Change to LargeFuelStation if required
+    }
 }
\ No newline at end of file
index 9bb7ff18d38df34536f79857454e6820b62401bf..44e9c2d8f9273dead610c4e0c3c74d33f54529d4 100644 (file)
@@ -40,4 +40,13 @@ public class MediumFuelStation extends FuelStation {
         super(number_of_employees, Size.MEDIUM, fuels);
         this.retail_space = retail_space;
     }
+
+    /**
+     * Getter method
+     * 
+     * @return retail space in m²
+     */
+    public float getRetail_space() {
+        return retail_space;
+    }
 }
index 9073c391e809cd79bccdab5b4b5f8160dce70991..dca0e79c9b15e3970a214f12ea1c3c3610b9cc64 100644 (file)
@@ -5,7 +5,7 @@ package de.diejungsvondertanke.tankstelle;
  */
 public class SmallFuelStation extends FuelStation {
     /**
-     * Number of drink vending machines 
+     * Number of drink vending machines
      */
     private short number_of_vending_machines;
 
@@ -36,4 +36,13 @@ public class SmallFuelStation extends FuelStation {
         super(number_of_employees, Size.SMALL, fuels);
         this.number_of_vending_machines = number_of_vending_machines;
     }
+
+    /**
+     * Getter method
+     * 
+     * @return the number of drink vending machines this fuel station has
+     */
+    public short getNumber_of_vending_machines() {
+        return number_of_vending_machines;
+    }
 }