import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
+import java.util.Arrays;
import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
/**
* (Initial) array of all {@link FuelStation}s
*/
- static FuelStation[] fuelStations = { new SmallFuelStation((short) 0), new SmallFuelStation((short) 0),
+ static FuelStation[] initialFuelStations = { new SmallFuelStation((short) 0), new SmallFuelStation((short) 0),
new MediumFuelStation(0), new MediumFuelStation(0), new MediumFuelStation(0),
new LargeFuelStation("PlatzhalterFirma1"), new LargeFuelStation("PlatzhalterFirma2"),
new LargeFuelStation("PlatzhalterFirma3") };
+ /**
+ * create an array list to store the fuel stations while the program is running
+ * add the initial array of fuel stations to the List
+ */
+ static ArrayList<FuelStation> fuelStations = new ArrayList<FuelStation>(Arrays.asList(initialFuelStations));
+
+
/**
* Main method
*
* @param args Program arguments (not in use)
*/
public static void main(String[] args) {
+
}
/**
* @author Nils Göbbert
*/
public static FuelStation getHighestPrice(FuelType fuelType) throws NoSuchFuelTypeError {
- float highestPrice = fuelStations[0].get_price(fuelType);
- FuelStation highestStation = fuelStations[0];
+ float highestPrice = fuelStations.toArray(new FuelStation[0])[0].get_price(fuelType);
+ FuelStation highestStation = fuelStations.toArray(new FuelStation[0])[0];
for (FuelStation fuelStation : fuelStations) {
if (fuelStation.get_price(fuelType) > highestPrice) {
highestPrice = fuelStation.get_price(fuelType);
* @author Nils Göbbert
*/
public static FuelStation getHighestAccumulatedValue() throws NoSuchFuelTypeError {
- float highestValue = fuelStations[0].get_cumulative_retail_price();
- FuelStation highestStation = fuelStations[0];
+ float highestValue = fuelStations.toArray(new FuelStation[0])[0].get_cumulative_retail_price();
+ FuelStation highestStation = fuelStations.toArray(new FuelStation[0])[0];
for (FuelStation fuelStation : fuelStations) {
if (fuelStation.get_cumulative_retail_price() > highestValue) {
highestValue = fuelStation.get_cumulative_retail_price();
* @author Nils Göbbert
*/
public static FuelStation getHighestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError {
- float highestAmount = fuelStations[0].getStored_amount(fuelType);
- FuelStation highestStation = fuelStations[0];
+ float highestAmount = fuelStations.toArray(new FuelStation[0])[0].getStored_amount(fuelType);
+ FuelStation highestStation = fuelStations.toArray(new FuelStation[0])[0];
for (FuelStation fuelStation : fuelStations) {
if (fuelStation.getStored_amount(fuelType) > highestAmount) {
highestAmount = fuelStation.getStored_amount(fuelType);
* @author Nils Göbbert
*/
public static FuelStation getLowestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError {
- float lowestAmount = fuelStations[0].getStored_amount(fuelType);
- FuelStation lowestStation = fuelStations[0];
+ float lowestAmount = fuelStations.toArray(new FuelStation[0])[0].getStored_amount(fuelType);
+ FuelStation lowestStation = fuelStations.toArray(new FuelStation[0])[0];
for (FuelStation fuelStation : fuelStations) {
if (fuelStation.getStored_amount(fuelType) > lowestAmount) {
lowestAmount = fuelStation.getStored_amount(fuelType);
*/
public static FuelStation[] getFuelStationListWhenUnderstaffed(short available_employees) {
ArrayList<FuelStation> result = new ArrayList<>();
- FuelStation[] fuelStationsLocalCopy = FuelStation.sortDescending(fuelStations);
+ FuelStation[] fuelStationsLocalCopy = FuelStation.sortDescending(fuelStations.toArray(new FuelStation[0]));
for (FuelStation station : fuelStationsLocalCopy) {
if (Math.floorDiv(available_employees, station.getNumber_of_employees()) >= 1) {
available_employees -= station.getNumber_of_employees();
}
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
+ }
+ 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
+ }
+ fuelStations.add(new MediumFuelStation(retail_space));
+ }
+
+ /**
+ * Add new 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
+ }
+ fuelStations.add(new SmallFuelStation(number_of_vending_machines));
+ }
+
+
+ /**
+ * 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
+ *
+ * @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){
+ sum += fuel.getStored_amount();
+ break;
+ }
+ }
+ }
+
+ return sum;
+ }
+
+
}
\ No newline at end of file