package de.diejungsvondertanke.tankstelle;
+import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
+
/**
* Abstract class.
* All fuel station subtypes inherit from this class.
this.fuels = fuels;
}
- public void set_stored_amount (float stored_amount, FuelType type){
-
+ public void set_stored_amount(float stored_amount, FuelType type) {
+
+ }
+
+ /**
+ * Set a new price for a specific type of fuel for this fuel station
+ *
+ * @param fuel_type The {@link FuelType} to change
+ * @param price The new price per litre
+ * @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 void set_price(FuelType fuel_type, float price) throws NoSuchFuelTypeError {
+ for (Fuel i : fuels) {
+ if (i.FUEL_TYPE == fuel_type) {
+ i.setPrice(price);
+ return;
+ }
+ }
+ throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type");
}
}
--- /dev/null
+package de.diejungsvondertanke.tankstelle.error;
+
+/**
+ * This Error is thrown on the attempt to choose a fuel type from a fuel station
+ * which the fuel station does not have
+ */
+public class NoSuchFuelTypeError extends Exception {
+ /**
+ * Throws a {@link NoSuchFuelTypeError}
+ *
+ * @param message Message to throw with this error
+ */
+ public NoSuchFuelTypeError(String message) {
+ super(message);
+ }
+
+ /**
+ * Throws a {@link NoSuchFuelTypeError}
+ */
+ public NoSuchFuelTypeError() {
+ super();
+ }
+}