this.size = size;
this.fuels = fuels;
}
-
- public void set_stored_amount(float stored_amount, FuelType type) {
-
+ /**
+ * Set a new fuel amount for a specific type of fuel for this fuel station
+ *
+ * @param type The {@link FuelType} to change
+ * @param new_amound The new fuel amound
+ * @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_stored_amount(float new_amount, FuelType type)throws NoSuchFuelTypeError {
+ for (Fuel i : fuels) {
+ if (i.FUEL_TYPE == type) {
+ i.setStored_amount(new_amount);
+ return;
+ }
+ throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type");
+ }
+ }
+ /**
+ * Add or subtract from a fuel amount for a specific type of fuel for this fuel station
+ *
+ * @param type The {@link FuelType} to change
+ * @param new_amound The aound of fuel that is added or subtracted
+ * @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 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");
+ }
+ i.setStored_amount(new_amount + i.getStored_amount());
+ return;
+ }
+ }
+ throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type");
}
/**