/**
* A fuel object. Contains fuel type, price per litre, stored fuel amount and
* storage capacity for this fuel
+ *
+ * @author Robin Cheney
*/
public class Fuel {
/**
* @param stored_amount Currently stored amount of fuel in L
* @param capacity Maximum fuel storage capacity in L
* @param price Retail price in € / L
+ *
+ * @author Robin Cheney
*/
public Fuel(FuelType fuel_type, float stored_amount, float price, int capacity) {
this.FUEL_TYPE = fuel_type;
* Getter method
*
* @return {@link FuelType FuelType} of this {@link Fuel Fuel}
+ *
+ * @deprecated
+ *
+ * @author Robin Cheney
*/
public FuelType getFuelType() {
return FUEL_TYPE;
* Getter method
*
* @return {@link #stored_amount stored amount of fuel}
+ *
+ * @author Robin Cheney
*/
public float getStored_amount() {
return stored_amount;
* Set new stored amount of fuel
*
* @param stored_amount New stored amount of fuel
+ *
+ * @author Robin Cheney
*/
public void setStored_amount(float stored_amount) {
this.stored_amount = stored_amount;
* Getter method
*
* @return {@link #CAPACITY Maximum fuel capacity}
+ *
+ * @deprecated
+ *
+ * @author Robin Cheney
*/
public int getCapacity() {
return CAPACITY;
* Getter method
*
* @return {@link #price price in € / L fuel}
+ *
+ * @author Robin Cheney
*/
public float getPrice() {
return price;
* Set new price in € / L fuel
*
* @param price New price in € / L fuel
+ *
+ * @author Robin Cheney
*/
public void setPrice(float price) {
this.price = price;
* @see LargeFuelStation
* @see MediumFuelStation
* @see SmallFuelStation
+ *
+ * @author Robin Cheney
+ * @author Nils Göbbert
*/
abstract class FuelStation {
/**
* @see LargeFuelStation
* @see MediumFuelStation
* @see SmallFuelStation
+ *
+ * @author Robin Cheney
*/
protected FuelStation(byte number_of_employees, Size size, Fuel[] fuels) {
this.number_of_employees = number_of_employees;
* @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
+ *
+ * @author Nils Göbbert
*/
public void set_stored_amount(float new_amount, FuelType type) throws NoSuchFuelTypeError {
for (Fuel i : fuels) {
* @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
+ *
+ * @author Nils Göbbert
*/
public void add_stored_amount(float new_amount, FuelType type) throws NoSuchFuelTypeError, ArithmeticException {
for (Fuel i : fuels) {
if (i.FUEL_TYPE == type) {
if (new_amount + i.getStored_amount() < 0) {
- throw new ArithmeticException("Fuel amound can't be negativ");
+ throw new ArithmeticException("Fuel amount can't be negative");
}
i.setStored_amount(new_amount + i.getStored_amount());
return;
* @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
+ *
+ * @author Robin Cheney
*/
public void set_price(FuelType fuel_type, float price) throws NoSuchFuelTypeError {
for (Fuel i : fuels) {
* @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
+ *
+ * @author Robin Cheney
*/
public float get_price(FuelType fuel_type) throws NoSuchFuelTypeError {
for (Fuel i : fuels) {
* current price(s)
*
* @return the income in €
+ *
+ * @author Robin Cheney
*/
public float get_cumulative_retail_price() {
float result = 0;
* Getter method
*
* @return {@link #number_of_employees}
+ *
+ * @author Robin Cheney
*/
public byte getNumber_of_employees() {
return number_of_employees;
*
* @param stations Array of {@link FuelStation}s
* @return an ordered array of {@link FuelStation}s
+ *
+ * @author Robin Cheney
+ */
+ public static FuelStation[] sortDescending(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]);
+ }
+
+ /**
+ * Sort the fuel stations by size in a ascending order (smallest stations first)
+ *
+ * @param stations Array of {@link FuelStation}s
+ * @return an ordered array of {@link FuelStation}s
+ *
+ * @author Robin Cheney
*/
- public static FuelStation[] sort(FuelStation[] stations) {
+ public static FuelStation[] sortAscending(FuelStation[] stations) {
ArrayList<FuelStation> result = new ArrayList<>();
ArrayList<FuelStation> large = new ArrayList<>();
ArrayList<FuelStation> medium = new ArrayList<>();
* @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
+ *
+ * @author Nils Göbbert
*/
public float getStored_amount(FuelType fuel_type) throws NoSuchFuelTypeError {
for (Fuel i : fuels) {
/**
* Possible {@link Fuel fuel} types
+ *
+ * @author Robin Cheney
*/
public enum FuelType {
/**
/**
* Large {@link FuelStation fuel station}
+ *
+ * @author Robin Cheney
*/
public class LargeFuelStation extends FuelStation {
/**
*
* @param supermarket_company The company managing the integrated supermarket
* @see #supermarket_company
+ *
+ * @author Robin Cheney
*/
public LargeFuelStation(String supermarket_company) {
super(NUMBER_OF_EMPLOYEES, Size.LARGE, new Fuel[] { new Fuel(FuelType.SUPER, 8000f, 1.7f, 16000),
* Getter method
*
* @return the name of the company running the integrated supermarket
+ *
+ * @author Robin Cheney
*/
public String getSupermarket_company() {
return supermarket_company;
/**
* Main Class
+ *
+ * @author Robin Cheney
+ * @author Nils Göbbert
*/
public class Main {
/**
new LargeFuelStation("PlatzhalterFirma1"), new LargeFuelStation("PlatzhalterFirma2"),
new LargeFuelStation("PlatzhalterFirma3") };
+ /**
+ * Main method
+ *
+ * @param args Program arguments (not in use)
+ */
public static void main(String[] args) {
}
* @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})
+ *
+ * @author Robin Cheney
*/
public static FuelStation[] getFuelStations(short number_of_vending_machines) {
ArrayList<FuelStation> result = new ArrayList<FuelStation>();
* @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})
+ *
+ * @author Robin Cheney
*/
public static FuelStation[] getFuelStations(float retail_space) {
ArrayList<FuelStation> result = new ArrayList<FuelStation>();
* @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})
+ *
+ * @author Robin Cheney
*/
public static FuelStation[] getFuelStations(String supermarket_company) {
ArrayList<FuelStation> result = new ArrayList<FuelStation>();
* @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
+ *
+ * @author Nils Göbbert
*/
public static FuelStation getHighestPrice(FuelType fuelType) throws NoSuchFuelTypeError {
float highestPrice = fuelStations[0].get_price(fuelType);
* @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
+ *
+ * @author Nils Göbbert
*/
public static FuelStation getHighestAccumulatedValue() throws NoSuchFuelTypeError {
float highestValue = fuelStations[0].get_cumulative_retail_price();
* @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
+ *
+ * @author Nils Göbbert
*/
public static FuelStation getHighestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError {
float highestAmount = fuelStations[0].getStored_amount(fuelType);
* @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
+ *
+ * @author Nils Göbbert
*/
public static FuelStation getLowestStoredAmount(FuelType fuelType) throws NoSuchFuelTypeError {
float lowestAmount = fuelStations[0].getStored_amount(fuelType);
* @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
+ *
+ * @author Robin Cheney
*/
public static boolean isPINCorrect(String pin) throws IOException {
* {@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
+ * @return All fuel stations that can reasonably be opened
+ *
+ * @author Robin Cheney
*/
public static FuelStation[] getFuelStationListWhenUnderstaffed(short available_employees) {
ArrayList<FuelStation> result = new ArrayList<>();
- FuelStation[] fuelStationsLocalCopy = FuelStation.sort(fuelStations);
+ FuelStation[] fuelStationsLocalCopy = FuelStation.sortDescending(fuelStations);
for (FuelStation station : fuelStationsLocalCopy) {
if (Math.floorDiv(available_employees, station.getNumber_of_employees()) >= 1) {
available_employees -= station.getNumber_of_employees();
* {@link FuelStation fuel station}s
*
* @return total staff count
+ *
+ * @author Robin Cheney
*/
public static int getTotalNumberOfEmployees() {
int sum = 0;
/**
* Medium {@link FuelStation fuel station}
+ *
+ * @author Robin Cheney
*/
public class MediumFuelStation extends FuelStation {
/**
*
* @param retail_space m² of retail space
* @see #retail_space retail_space
+ *
+ * @author Robin Cheney
*/
public MediumFuelStation(float retail_space) {
super(NUMBER_OF_EMPLOYEES, Size.MEDIUM, new Fuel[] { new Fuel(FuelType.SUPER, 6000f, 1.7f, 12000),
* Getter method
*
* @return retail space in m²
+ *
+ * @author Robin Cheney
*/
public float getRetail_space() {
return retail_space;
* @see LargeFuelStation
* @see MediumFuelStation
* @see SmallFuelStation
+ *
+ * @author Robin Cheney
*/
public enum Size {
/**
/**
* Small {@link FuelStation fuel station}
+ *
+ * @author Robin Cheney
*/
public class SmallFuelStation extends FuelStation {
/**
*
* @param number_of_vending_machines Number of drink vending machines
* @see #number_of_vending_machines
+ *
+ * @author Robin Cheney
*/
public SmallFuelStation(short number_of_vending_machines) {
super(NUMBER_OF_EMPLOYEES, Size.SMALL, new Fuel[] { new Fuel(FuelType.SUPER, 4000f, 1.68f, 8000),
* Getter method
*
* @return the number of drink vending machines this fuel station has
+ *
+ * @author Robin Cheney
*/
public short getNumber_of_vending_machines() {
return number_of_vending_machines;
/**
* This Error is thrown on the attempt to choose a fuel type from a fuel station
* which the fuel station does not have
+ *
+ * @author Robin Cheney
*/
public class NoSuchFuelTypeError extends Exception {
/**
* Throws a {@link NoSuchFuelTypeError}
*
* @param message Message to throw with this error
+ *
+ * @author Robin Cheney
*/
public NoSuchFuelTypeError(String message) {
super(message);
/**
* Throws a {@link NoSuchFuelTypeError}
+ *
+ * @author Robin Cheney
*/
public NoSuchFuelTypeError() {
super();