From: Robin Date: Mon, 10 Nov 2025 10:11:07 +0000 (+0100) Subject: Added get_price method in FuelStation X-Git-Url: https://git.eternal.ddnss.de/?a=commitdiff_plain;h=81a6347bfa8cb70203e4b9c9b53575146cb949b6;p=tankstelle.git Added get_price method in FuelStation --- diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java b/src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java index 00eb456..31be9e6 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java @@ -70,4 +70,21 @@ abstract class FuelStation { throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type"); } + /** + * Get the price for a specific type of fuel for this fuel station + * + * @param fuel_type The {@link FuelType} to get + * @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 float get_price(FuelType fuel_type) throws NoSuchFuelTypeError { + for (Fuel i : fuels) { + if (i.FUEL_TYPE == fuel_type) { + return i.getPrice(); + } + } + throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type"); + } + }