From c60c85ade063aaee23f868327394923af37b4598 Mon Sep 17 00:00:00 2001 From: peet Date: Tue, 21 May 2024 14:18:10 +0000 Subject: [PATCH 1/2] updated uebung05 from lsg --- src/uebung05/logistics/Demo.java | 37 +++- src/uebung05/logistics/Helicopter.java | 115 +++++++++++- src/uebung05/logistics/Manager.java | 120 +++++++++++++ src/uebung05/logistics/NeedCollector.java | 68 +++---- src/uebung05/logistics/Tank.java | 113 +++++++++++- src/uebung05/logistics/Truck.java | 109 ++++++++++-- src/uebung05/logistics/Vehicle.java | 109 ++++++++++-- .../logistics/material/BulletBelts.java | 47 +++-- src/uebung05/logistics/material/Grease.java | 48 +++-- .../logistics/material/LiterDiesel.java | 48 +++-- .../material/MetGallonsKerosene.java | 48 +++-- src/uebung05/logistics/material/Oil.java | 47 +++-- .../logistics/material/RocketPods.java | 62 +++++-- .../logistics/material/ShellBatches.java | 61 +++++-- .../logistics/quantities/FloatUnit.java | 6 +- .../logistics/quantities/IntUnit.java | 8 +- .../logistics/quantities/NeedCollector.java | 108 ++++++++++++ src/uebung05/logistics/quantities/Unit.java | 7 + .../logistics/storage/FloatStorage.java | 164 ++++++++++++----- .../logistics/storage/IntStorage.java | 166 +++++++++++++----- 20 files changed, 1209 insertions(+), 282 deletions(-) mode change 100644 => 100755 src/uebung05/logistics/Demo.java mode change 100644 => 100755 src/uebung05/logistics/Helicopter.java create mode 100755 src/uebung05/logistics/Manager.java mode change 100644 => 100755 src/uebung05/logistics/NeedCollector.java mode change 100644 => 100755 src/uebung05/logistics/Tank.java mode change 100644 => 100755 src/uebung05/logistics/Truck.java mode change 100644 => 100755 src/uebung05/logistics/Vehicle.java mode change 100644 => 100755 src/uebung05/logistics/material/BulletBelts.java mode change 100644 => 100755 src/uebung05/logistics/material/Grease.java mode change 100644 => 100755 src/uebung05/logistics/material/LiterDiesel.java mode change 100644 => 100755 src/uebung05/logistics/material/MetGallonsKerosene.java mode change 100644 => 100755 src/uebung05/logistics/material/Oil.java mode change 100644 => 100755 src/uebung05/logistics/material/RocketPods.java mode change 100644 => 100755 src/uebung05/logistics/material/ShellBatches.java mode change 100644 => 100755 src/uebung05/logistics/quantities/FloatUnit.java mode change 100644 => 100755 src/uebung05/logistics/quantities/IntUnit.java create mode 100755 src/uebung05/logistics/quantities/NeedCollector.java create mode 100755 src/uebung05/logistics/quantities/Unit.java mode change 100644 => 100755 src/uebung05/logistics/storage/FloatStorage.java mode change 100644 => 100755 src/uebung05/logistics/storage/IntStorage.java diff --git a/src/uebung05/logistics/Demo.java b/src/uebung05/logistics/Demo.java old mode 100644 new mode 100755 index beded21..9081424 --- a/src/uebung05/logistics/Demo.java +++ b/src/uebung05/logistics/Demo.java @@ -1,9 +1,38 @@ -package uebung05.logistics; +package logistics; -public class Demo { +import logistics.material.BulletBelts; +import logistics.material.LiterDiesel; +import logistics.material.RocketPods; + +class demo { public static void main(String[] args) { - - } + Manager ceo = new Manager(); + Vehicle panther = new Tank("Panther"); + Vehicle leo = new Tank("Leopard 2A7"); + Vehicle tiger = new Helicopter("Tiger"); + Vehicle h125m = new Helicopter("H145M"); + Vehicle husky = new Truck("BV206-S Hägglunds"); + Vehicle zwoTonner = new Truck("Unimog2000"); + + ceo.addVehicle(panther); + ceo.addVehicle(leo); + ceo.addVehicle(tiger); + ceo.addVehicle(h125m); + ceo.addVehicle(husky); + ceo.addVehicle(zwoTonner); + + ceo.showOverallNeed(); + ceo.showNeed(LiterDiesel.getINSTANCE()); + ceo.fillUpVehicles(); + ceo.showOverallNeed(); + ceo.logTick(2); + ceo.showOverallNeed(); + ceo.showNeed(RocketPods.getINSTANCE()); + ceo.fillUpVehicles(); + ceo.logTick(1); + ceo.showOverallNeed(); + ceo.showNeed(BulletBelts.getINSTANCE()); + } } diff --git a/src/uebung05/logistics/Helicopter.java b/src/uebung05/logistics/Helicopter.java old mode 100644 new mode 100755 index b8b56bf..8d53e33 --- a/src/uebung05/logistics/Helicopter.java +++ b/src/uebung05/logistics/Helicopter.java @@ -1,5 +1,114 @@ -package uebung05.logistics; +package logistics; -public class Helicopter extends Vehicle{ +import logistics.material.BulletBelts; +import logistics.material.MetGallonsKerosene; +import logistics.material.RocketPods; +import logistics.quantities.FloatUnit; +import logistics.quantities.IntUnit; +import logistics.quantities.NeedCollector; +import logistics.storage.FloatStorage; +import logistics.storage.IntStorage; -} +/** + * The Helicopter class represents a helicopter in the logistics system. + * It extends the Vehicle abstract class and includes a tank for kerosene, + * a storage for bullet belts, and a storage for rocket pods, and the necessary methods + * for reporting needs, filling up, and consuming supplies. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class Helicopter extends Vehicle { + + FloatStorage tank; + IntStorage bullets; + IntStorage rockets; + + private final static int maxAmmunition = 2; + private final static int maxFuel = 500; + + /** + * Construct a Helicopter object with a name, kerosene amount, bullet belts amount, and rocket pods amount + * + * @param name The name of the helicopter + * @param kerosine The initial amount of kerosene for the helicopter + * @param bulletsBelts The initial amount of bullet belts for the helicopter + * @param rocketPods The initial amount of rocket pods for the helicopter + */ + public Helicopter(String name, float kerosine, int bulletsBelts, int rocketPods) { + super(name, 3, 3); + + this.bullets = new IntStorage(bulletsBelts, BulletBelts.getINSTANCE(), maxAmmunition); + this.rockets = new IntStorage(rocketPods, RocketPods.getINSTANCE(), maxAmmunition); + this.tank = new FloatStorage(kerosine, MetGallonsKerosene.getINSTANCE(), maxFuel); + } + + /** + * Construct a Helicopter object with a name, kerosene amount, bullet belts amount, and rocket pods amount + * + * @param name The name of the helicopter + */ + public Helicopter(String name) { + this(name, 0, 0, 0); + } + + /** + * Report the needs of the helicopter to a NeedCollector object + * + * @param collector The NeedCollector object to which to report the needs + */ + @Override + public void reportNeeds(NeedCollector collector) { + tank.reportNeed(collector); + bullets.reportNeed(collector); + rockets.reportNeed(collector); + super.reportBasicNeeds(collector); + } + + /** + * Fill up all the supplies for the helicopter + */ + @Override + public void fillUpAll() { + tank.fillUp(); + bullets.fillUp(); + rockets.fillUp(); + super.fillUpBasic(); + + } + + /** + * Consume the helicopter's supplies based on the intensity rate + * + * @param intensityRate The intensity rate for the consumption + */ + @Override + public void consumeAll(int intensityRate) { + tank.consume(intensityRate*200); + bullets.consume(intensityRate); + rockets.consume(intensityRate); + super.consumeBasic(); + } + + /** + * Check if the helicopter needs a specific IntUnit object + * + * @param unit The IntUnit object for which to check the need + * @return True if the helicopter needs the IntUnit object, false otherwise + */ + @Override + public Boolean need(IntUnit unit) { + return unit == bullets.getUnit() || unit == rockets.getUnit() || unit == oil.getUnit() || unit == grease.getUnit(); + } + + /** + * Check if the helicopter needs a specific FloatUnit object + * + * @param unit The FloatUnit object for which to check the need + * @return True if the helicopter needs the FloatUnit object, false otherwise + */ + @Override + public Boolean need(FloatUnit unit) { + return unit == tank.getUnit(); + } +} \ No newline at end of file diff --git a/src/uebung05/logistics/Manager.java b/src/uebung05/logistics/Manager.java new file mode 100755 index 0000000..b954c8e --- /dev/null +++ b/src/uebung05/logistics/Manager.java @@ -0,0 +1,120 @@ +package logistics; + +import logistics.quantities.FloatUnit; +import logistics.quantities.IntUnit; +import logistics.quantities.NeedCollector; +import logistics.quantities.Unit; + +import java.util.ArrayList; +import java.util.List; + +/** + * The Manager class manages a list of Vehicle objects and provides methods for adding, filling up, and logging ticks for the vehicles. + * It also includes methods for collecting and displaying the overall needs of the vehicles and the needs for specific IntUnit or FloatUnit objects. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class Manager { + + private List vehicles; + + public Manager() { + this.vehicles = new ArrayList<>(); + } + + /** + * Add a Vehicle object to the list of vehicles + * + * @param vehicle The Vehicle object to be added + */ + public void addVehicle(Vehicle vehicle) { + vehicles.add(vehicle); + System.out.println("Boris bought a new " + vehicle.getClass().getSimpleName() + " " + vehicle + "."); + System.out.println(); + } + + /** + * Fill up all the vehicles in the list + */ + public void fillUpVehicles() { + for (Vehicle vehicle : vehicles) { + vehicle.fillUpAll(); + } + System.out.println("All vehicles filled and ready for combat."); + System.out.println(); + } + + /** + * Log a tick for all the vehicles in the list, consuming their supplies based on the intensity rate + * + * @param intensityRate The intensity rate for the tick + */ + public void logTick(int intensityRate) { + for (Vehicle vehicle : vehicles) { + vehicle.consumeAll(intensityRate); + } + System.out.println("All vehicles consumed because of " + intensityRate + " battle(s)."); + System.out.println(); + } + + /** + * Collect the needs of all the vehicles in the list and return a NeedCollector object + * + * @return The NeedCollector object containing the needs of all the vehicles + */ + NeedCollector collectNeeds() { + NeedCollector collector = new NeedCollector(); + for (Vehicle vehicle : vehicles) { + vehicle.reportNeeds(collector); + } + return collector; + } + + /** + * Display the overall needs of all the vehicles in the list + */ + public void showOverallNeed() { + NeedCollector collector = collectNeeds(); + collector.show(); + } + + /** + * Display the vehicles needing a specific IntUnit object + * + * @param unit The IntUnit object for which to display the vehicles + */ + public void showNeed(IntUnit unit) { + /*if (unit instanceof IntUnit) { + IntUnit intUnit = (IntUnit) unit; + } else if (unit instanceof FloatUnit) { + FloatUnit floatUnit = (FloatUnit) unit; + }*/ + System.out.println("Vehicles needing " + unit.toString() + ":"); + for (Vehicle vehicle : vehicles) { + if (vehicle.need(unit)) { + NeedCollector collector = new NeedCollector(); + vehicle.reportNeeds(collector); + System.out.println("- " + vehicle + " needs " + collector.getNeed(unit) + " " + unit); + } + } + System.out.println(); + } + + /** + * Display the vehicles needing a specific FloatUnit object + * + * @param unit The FloatUnit object for which to display the vehicles + */ + public void showNeed(FloatUnit unit) { + System.out.println("Vehicles needing " + unit.toString() + ":"); + for (Vehicle vehicle : vehicles) { + if (vehicle.need(unit)) { + NeedCollector collector = new NeedCollector(); + vehicle.reportNeeds(collector); + System.out.println("- " + vehicle + " needs " + collector.getNeed(unit) + " " + unit); + } + } + System.out.println(); + } +} \ No newline at end of file diff --git a/src/uebung05/logistics/NeedCollector.java b/src/uebung05/logistics/NeedCollector.java old mode 100644 new mode 100755 index 7294621..0aec1bc --- a/src/uebung05/logistics/NeedCollector.java +++ b/src/uebung05/logistics/NeedCollector.java @@ -1,60 +1,38 @@ -package uebung05.logistics; +package logistics; +import logistics.quantities.FloatUnit; +import logistics.quantities.IntUnit; + +import java.util.HashMap; import java.util.Map; -import uebung05.logistics.quantities.FloatUnit; -import uebung05.logistics.quantities.IntUnit; - public class NeedCollector { + private Map intNeeded; private Map floatNeeded; - - /** - * add specific amount of operating material - * - * @param amount amount to be added - * @param unit type of operating material to be added - */ - public void add(int amount, IntUnit unit) { - - } - - /** - * add specific amount of operating material - * - * @param amount amount to be added - * @param unit type of operating material to be added - */ - public void add(float amount, FloatUnit unit) { - + public NeedCollector() { + intNeeded = new HashMap<>(); + floatNeeded = new HashMap<>(); } - /** - * get the need of a specific operating material - * - * @param unit the type of operating material - * @return all the needs of the specific material - */ - public int getNeeded(IntUnit unit) { - return 0; + public void add (int amount, IntUnit unit) { + intNeeded.put(unit, amount); } - /** - * get the need of a specific operating material - * - * @param unit the type of operating material - * @return all the needs of the specific material - */ - public float getNeeded(FloatUnit unit) { - return 0; + public void add (float amount, FloatUnit unit) { + floatNeeded.put(unit, amount); } - /** - * Prints the total requirements in the therminal - * - */ - public void show(){ + public int getNeed (IntUnit unit) { + return intNeeded.get(unit); + } + + public float getNeed (FloatUnit unit) { + return floatNeeded.get(unit); + } + + public void show () { } -} \ No newline at end of file +} diff --git a/src/uebung05/logistics/Tank.java b/src/uebung05/logistics/Tank.java old mode 100644 new mode 100755 index c6a2d79..489875a --- a/src/uebung05/logistics/Tank.java +++ b/src/uebung05/logistics/Tank.java @@ -1,5 +1,112 @@ -package uebung05.logistics; +package logistics; -public class Tank extends Vehicle{ +import logistics.material.BulletBelts; +import logistics.material.LiterDiesel; +import logistics.material.ShellBatches; +import logistics.quantities.FloatUnit; +import logistics.quantities.IntUnit; +import logistics.quantities.NeedCollector; +import logistics.storage.FloatStorage; +import logistics.storage.IntStorage; -} +/** + * The Tank class represents a tank in the logistics system. + * It extends the Vehicle abstract class and includes a tank for diesel, a storage for bullet belts, + * and a storage for shell batches, and the necessary methods for reporting needs, filling up, and consuming supplies. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class Tank extends Vehicle { + + FloatStorage tank; + IntStorage shell; + IntStorage bullets; + + private final static int maxAmmunition = 10; + private final static int maxFuel = 1200; + + /** + * Construct a Tank object with a name, diesel amount, bullet belts amount, and shell batches amount + * + * @param name The name of the tank + * @param diesel The initial amount of diesel for the tank + * @param bulletBelts The initial amount of bullet belts for the tank + * @param shellBatches The initial amount of shell batches for the tank + */ + public Tank(String name, float diesel, int bulletBelts, int shellBatches) { + super(name, 3, 3); + + this.shell = new IntStorage(shellBatches, ShellBatches.getINSTANCE(), maxAmmunition); + this.bullets = new IntStorage(bulletBelts, BulletBelts.getINSTANCE(), maxAmmunition); + this.tank = new FloatStorage(diesel, LiterDiesel.getINSTANCE(), maxFuel); + } + + /** + * Construct a Tank object with a name + * + * @param name The name of the tank + */ + public Tank(String name) { + this(name, 0, 0, 0); + } + + /** + * Report the needs of the tank to a NeedCollector object + * + * @param collector The NeedCollector object to which to report the needs + */ + @Override + public void reportNeeds(NeedCollector collector) { + tank.reportNeed(collector); + shell.reportNeed(collector); + bullets.reportNeed(collector); + super.reportBasicNeeds(collector); + } + + /** + * Fill up all the supplies for the tank + */ + @Override + public void fillUpAll() { + tank.fillUp(); + shell.fillUp(); + bullets.fillUp(); + super.fillUpBasic(); + } + + /** + * Consume the tank's supplies based on the intensity rate + * + * @param intensityRate The intensity rate for the consumption + */ + @Override + public void consumeAll(int intensityRate) { + tank.consume(intensityRate*180); + bullets.consume(intensityRate*2); + shell.consume(intensityRate*2); + super.consumeBasic(); + } + + /** + * Check if the tank needs a specific IntUnit object + * + * @param unit The IntUnit object for which to check the need + * @return True if the tank needs the IntUnit object, false otherwise + */ + @Override + public Boolean need(IntUnit unit) { + return unit == shell.getUnit() || unit == bullets.getUnit() || unit == oil.getUnit() || unit == grease.getUnit(); + } + + /** + * Check if the tank needs a specific FloatUnit object + * + * @param unit The FloatUnit object for which to check the need + * @return True if the tank needs the FloatUnit object, false otherwise + */ + @Override + public Boolean need(FloatUnit unit) { + return unit == tank.getUnit(); + } +} \ No newline at end of file diff --git a/src/uebung05/logistics/Truck.java b/src/uebung05/logistics/Truck.java old mode 100644 new mode 100755 index eaf8d62..83deb6e --- a/src/uebung05/logistics/Truck.java +++ b/src/uebung05/logistics/Truck.java @@ -1,17 +1,104 @@ -package uebung05.logistics; +package logistics; -import java.util.HashMap; -import java.util.Map; - -import uebung05.logistics.material.Oil; -import uebung05.logistics.quantities.IntUnit; +import logistics.material.BulletBelts; +import logistics.material.LiterDiesel; +import logistics.quantities.FloatUnit; +import logistics.quantities.IntUnit; +import logistics.quantities.NeedCollector; +import logistics.storage.FloatStorage; +import logistics.storage.IntStorage; +/** + * The Truck class represents a truck in the logistics system. + * It extends the Vehicle abstract class and includes a tank for diesel, a storage for bullet belts, and the necessary methods for reporting needs, filling up, and consuming supplies. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ public class Truck extends Vehicle { - public Truck(String name){ - this.name = name; - materials = new HashMap<>(); - materials.put(Oil.getInstance(0), 5); + FloatStorage tank; + IntStorage bullets; + + private final static int maxAmmunition = 3; + private final static int maxFuel = 180; + + /** + * Construct a Truck object with a name, diesel amount, and bullet belts amount + * + * @param name The name of the truck + * @param diesel The initial amount of diesel for the truck + * @param bulletBelts The initial amount of bullet belts for the truck + */ + public Truck(String name, float diesel, int bulletBelts) { + super(name, 3, 3); + + tank = new FloatStorage(diesel, LiterDiesel.getINSTANCE(), maxFuel); + bullets = new IntStorage(bulletBelts, BulletBelts.getINSTANCE(), maxAmmunition); } -} + /** + * Construct a Truck object with a name, diesel amount, and bullet belts amount + * + * @param name The name of the truck + */ + public Truck(String name) { + this(name, 0, 0); + } + + /** + * Report the needs of the truck to a NeedCollector object + * + * @param collector The NeedCollector object to which to report the needs + */ + @Override + public void reportNeeds(NeedCollector collector) { + tank.reportNeed(collector); + bullets.reportNeed(collector); + super.reportBasicNeeds(collector); + } + + /** + * Fill up all the supplies for the truck + */ + @Override + public void fillUpAll() { + tank.fillUp(); + bullets.fillUp(); + super.fillUpBasic(); + } + + /** + * Consume the truck's supplies based on the intensity rate + * + * @param intensityRate The intensity rate for the consumption + */ + @Override + public void consumeAll(int intensityRate) { + tank.consume(intensityRate*25); + bullets.consume(intensityRate*2); + super.consumeBasic(); + } + + /** + * Check if the truck needs a specific IntUnit object + * + * @param unit The IntUnit object for which to check the need + * @return True if the truck needs the IntUnit object, false otherwise + */ + @Override + public Boolean need(IntUnit unit) { + return unit == bullets.getUnit() || unit == oil.getUnit() || unit == grease.getUnit(); + } + + /** + * Check if the truck needs a specific FloatUnit object + * + * @param unit The FloatUnit object for which to check the need + * @return True if the truck needs the FloatUnit object, false otherwise + */ + @Override + public Boolean need(FloatUnit unit) { + return unit == tank.getUnit(); + } +} \ No newline at end of file diff --git a/src/uebung05/logistics/Vehicle.java b/src/uebung05/logistics/Vehicle.java old mode 100644 new mode 100755 index c285514..6ae0002 --- a/src/uebung05/logistics/Vehicle.java +++ b/src/uebung05/logistics/Vehicle.java @@ -1,16 +1,105 @@ -package uebung05.logistics; +package logistics; -import java.util.Map; +import logistics.material.Grease; +import logistics.material.Oil; +import logistics.quantities.FloatUnit; +import logistics.quantities.IntUnit; +import logistics.quantities.NeedCollector; +import logistics.storage.IntStorage; -import uebung05.logistics.quantities.IntUnit; +/** + * The Vehicle abstract class represents a vehicle in the logistics system. + * It includes an abstract reportNeeds method for reporting the needs of the vehicle, + * an abstract fillUpAll method for filling up the vehicle, an abstract consumeAll method for + * consuming the vehicle's supplies, and abstract need methods for checking if the vehicle needs + * a specific IntUnit or FloatUnit object. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public abstract class Vehicle { -public abstract class Vehicle{ - protected String name; - protected Map materials; + String name; + IntStorage oil; + IntStorage grease; - protected abstract void reportNeeds(NeedCollector collector); + private final static int maxOil = 3; + private final static int maxGrease = 3; - protected abstract void fillUpAll(); + /** + * Construct a Vehicle object with a name, oil storage, and grease storage + * + * @param name The name of the vehicle + * @param oil The initial amount of oil for the vehicle + * @param grease The initial amount of grease for the vehicle + */ + protected Vehicle(String name, int oil, int grease) { + this.name = name; + this.oil = new IntStorage(oil, Oil.getINSTANCE(), maxOil); + this.grease = new IntStorage(grease, Grease.getINSTANCE(), maxGrease); + } - protected abstract void consumeAll(int intensityRate); -} + /** + * Fill up oil and grease. + */ + public void fillUpBasic () { + oil.fillUp(); + grease.fillUp(); + } + + /** + * Consume oil and grease. + */ + public void consumeBasic () { + oil.consume(1); + grease.consume(1); + } + + /** + * Report needs of oil and grease. + */ + public void reportBasicNeeds (NeedCollector collector) { + oil.reportNeed(collector); + grease.reportNeed(collector); + } + + /** + * Report the needs of the vehicle to a NeedCollector object + * + * @param collector The NeedCollector object to which to report the needs + */ + public abstract void reportNeeds(NeedCollector collector); + + /** + * Fill up all the supplies for the vehicle + */ + public abstract void fillUpAll(); + + /** + * Consume the vehicle's supplies based on the intensity rate + * + * @param intensityRate The intensity rate for the consumption + */ + public abstract void consumeAll(int intensityRate); + + /** + * Check if the vehicle needs a specific IntUnit object + * + * @param unit The IntUnit object for which to check the need + * @return True if the vehicle needs the IntUnit object, false otherwise + */ + public abstract Boolean need(IntUnit unit); + + /** + * Check if the vehicle needs a specific FloatUnit object + * + * @param unit The FloatUnit object for which to check the need + * @return True if the vehicle needs the FloatUnit object, false otherwise + */ + public abstract Boolean need(FloatUnit unit); + + @Override + public String toString() { + return name; + } +} \ No newline at end of file diff --git a/src/uebung05/logistics/material/BulletBelts.java b/src/uebung05/logistics/material/BulletBelts.java old mode 100644 new mode 100755 index d44dc5c..7df7b9b --- a/src/uebung05/logistics/material/BulletBelts.java +++ b/src/uebung05/logistics/material/BulletBelts.java @@ -1,24 +1,39 @@ -package uebung05.logistics.material; +package logistics.material; -import uebung05.logistics.quantities.IntUnit; +import logistics.quantities.IntUnit; -public class BulletBelts implements IntUnit{ - private static BulletBelts instance; - private int amount; +/** + * The BulletBelts class represents a unit of measurement for 7.62 bullets. + * It is a singleton class, meaning only one instance of the class can exist at a time. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class BulletBelts implements IntUnit { - private BulletBelts(int amount){ - this.amount = amount; + private static BulletBelts INSTANCE; + + private BulletBelts() {} + + /** + * Get the singleton instance of the BulletBelts class + * + * @return The singleton instance of the BulletBelts class + */ + public static BulletBelts getINSTANCE() { + if (INSTANCE == null) { + INSTANCE = new BulletBelts(); + } + return INSTANCE; } + /** + * Get a string representation of the BulletBelts object + * + * @return A string representation of the BulletBelts object + */ @Override public String toString() { - return amount + " belts of 7.62 bullets"; + return "belts of 7.62 bullets"; } - - public static BulletBelts getInstance(int amount){ - if (instance == null){ - instance = new BulletBelts(amount); - } - return instance; - } -} +} \ No newline at end of file diff --git a/src/uebung05/logistics/material/Grease.java b/src/uebung05/logistics/material/Grease.java old mode 100644 new mode 100755 index 4584cf2..d752195 --- a/src/uebung05/logistics/material/Grease.java +++ b/src/uebung05/logistics/material/Grease.java @@ -1,25 +1,39 @@ -package uebung05.logistics.material; +package logistics.material; -import uebung05.logistics.quantities.IntUnit; +import logistics.quantities.IntUnit; -public class Grease implements IntUnit{ - private static Grease instance; - private int amount; +/** + * The Grease class represents a unit of measurement for grease. + * It is a singleton class, meaning only one instance of the class can exist at a time. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class Grease implements IntUnit { - private Grease(int amount){ - this.amount = amount; + private static Grease INSTANCE; + + private Grease() {} + + /** + * Get the singleton instance of the Grease class + * + * @return The singleton instance of the Grease class + */ + public static Grease getINSTANCE() { + if (INSTANCE == null) { + INSTANCE = new Grease(); + } + return INSTANCE; } + /** + * Get a string representation of the Grease object + * + * @return A string representation of the Grease object + */ @Override public String toString() { - return amount + " units of grease"; + return "units of grease"; } - - public static Grease getInstance(int amount){ - if (instance == null){ - instance = new Grease(amount); - } - return instance; - } - -} +} \ No newline at end of file diff --git a/src/uebung05/logistics/material/LiterDiesel.java b/src/uebung05/logistics/material/LiterDiesel.java old mode 100644 new mode 100755 index 63184af..2e16e58 --- a/src/uebung05/logistics/material/LiterDiesel.java +++ b/src/uebung05/logistics/material/LiterDiesel.java @@ -1,25 +1,39 @@ -package uebung05.logistics.material; +package logistics.material; -import uebung05.logistics.quantities.FloatUnit; +import logistics.quantities.FloatUnit; -public class LiterDiesel implements FloatUnit{ - private static LiterDiesel instance; - private float amount; +/** + * The LiterDiesel class represents a unit of measurement for diesel fuel. + * It is a singleton class, meaning only one instance of the class can exist at a time. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class LiterDiesel implements FloatUnit { - private LiterDiesel(float amount){ - this.amount = amount; + private static LiterDiesel INSTANCE; + + private LiterDiesel() {} + + /** + * Get the singleton instance of the LiterDiesel class + * + * @return The singleton instance of the LiterDiesel class + */ + public static LiterDiesel getINSTANCE() { + if (INSTANCE == null) { + INSTANCE = new LiterDiesel(); + } + return INSTANCE; } + /** + * Get a string representation of the LiterDiesel object + * + * @return A string representation of the LiterDiesel object + */ @Override public String toString() { - return amount + " liters of diesel"; + return "liters of diesel"; } - - public static LiterDiesel getInstance(float amount){ - if (instance == null){ - instance = new LiterDiesel(amount); - } - return instance; - } - -} +} \ No newline at end of file diff --git a/src/uebung05/logistics/material/MetGallonsKerosene.java b/src/uebung05/logistics/material/MetGallonsKerosene.java old mode 100644 new mode 100755 index a9c2d3a..a50399c --- a/src/uebung05/logistics/material/MetGallonsKerosene.java +++ b/src/uebung05/logistics/material/MetGallonsKerosene.java @@ -1,25 +1,39 @@ -package uebung05.logistics.material; +package logistics.material; -import uebung05.logistics.quantities.FloatUnit; +import logistics.quantities.FloatUnit; -public class MetGallonsKerosene implements FloatUnit{ - private static MetGallonsKerosene instance; - private float amount; +/** + * The MetGallonsKerosene class represents a unit of measurement for kerosene. + * It is a singleton class, meaning only one instance of the class can exist at a time. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class MetGallonsKerosene implements FloatUnit { - private MetGallonsKerosene(float amount){ - this.amount = amount; + private static MetGallonsKerosene INSTANCE; + + private MetGallonsKerosene() {} + + /** + * Get the singleton instance of the MetGallonsKerosene class + * + * @return The singleton instance of the MetGallonsKerosene class + */ + public static MetGallonsKerosene getINSTANCE() { + if (INSTANCE == null) { + INSTANCE = new MetGallonsKerosene(); + } + return INSTANCE; } + /** + * Get a string representation of the MetGallonsKerosene object + * + * @return A string representation of the MetGallonsKerosene object + */ @Override public String toString() { - return amount + " met gallons of kerosene"; + return "met gallons of kerosene"; } - - public static MetGallonsKerosene getInstance(float amount){ - if (instance == null){ - instance = new MetGallonsKerosene(amount); - } - return instance; - } - -} +} \ No newline at end of file diff --git a/src/uebung05/logistics/material/Oil.java b/src/uebung05/logistics/material/Oil.java old mode 100644 new mode 100755 index acb4cd4..4f991b1 --- a/src/uebung05/logistics/material/Oil.java +++ b/src/uebung05/logistics/material/Oil.java @@ -1,24 +1,39 @@ -package uebung05.logistics.material; +package logistics.material; -import uebung05.logistics.quantities.IntUnit; +import logistics.quantities.IntUnit; -public class Oil implements IntUnit{ - private static Oil instance; - private int amount; +/** + * The Oil class represents a unit of measurement for oil. + * It is a singleton class, meaning only one instance of the class can exist at a time. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class Oil implements IntUnit { - private Oil(int amount){ - this.amount = amount; + private static Oil INSTANCE; + + private Oil() {} + + /** + * Get the singleton instance of the Oil class + * + * @return The singleton instance of the Oil class + */ + public static Oil getINSTANCE() { + if (INSTANCE == null) { + INSTANCE = new Oil(); + } + return INSTANCE; } + /** + * Get a string representation of the Oil object + * + * @return A string representation of the Oil object + */ @Override public String toString() { - return amount + " units of oil"; + return "units of oil"; } - - public static Oil getInstance(int amount){ - if (instance == null){ - instance = new Oil(amount); - } - return instance; - } -} +} \ No newline at end of file diff --git a/src/uebung05/logistics/material/RocketPods.java b/src/uebung05/logistics/material/RocketPods.java old mode 100644 new mode 100755 index 229f1db..44f07b3 --- a/src/uebung05/logistics/material/RocketPods.java +++ b/src/uebung05/logistics/material/RocketPods.java @@ -1,24 +1,58 @@ -package uebung05.logistics.material; +package logistics.material; -import uebung05.logistics.quantities.IntUnit; +import logistics.quantities.IntUnit; -public class RocketPods implements IntUnit{ - private static RocketPods instance; - private int amount; +/** + * The RocketPods class represents a unit of measurement for 70mm rocket pods. + * It is a singleton class, meaning only one instance of the class can exist at a time. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class RocketPods implements IntUnit { - private RocketPods(int amount){ - this.amount = amount; + private static RocketPods INSTANCE; + + private RocketPods() {} + + /** + * Get the singleton instance of the RocketPods class + * + * @return The singleton instance of the RocketPods class + */ + public static RocketPods getINSTANCE() { + if (INSTANCE == null) { + INSTANCE = new RocketPods(); + } + return INSTANCE; } + /** + * Get a string representation of the RocketPods object + * + * @return A string representation of the RocketPods object + */ @Override public String toString() { - return amount + " pods of 70mm rockets"; + return "pods of 70mm rockets"; } - public static RocketPods getInstance(int amount){ - if (instance == null){ - instance = new RocketPods(amount); - } - return instance; + /** + * Set the integer value of the RocketPods object + * + * @param value The integer value to set + */ + public void setValue(int value) { + // Implementation goes here } -} + + /** + * Get the integer value of the RocketPods object + * + * @return The integer value of the RocketPods object + */ + public int getValue() { + // Implementation goes here + return 0; + } +} \ No newline at end of file diff --git a/src/uebung05/logistics/material/ShellBatches.java b/src/uebung05/logistics/material/ShellBatches.java old mode 100644 new mode 100755 index d411659..ee6f820 --- a/src/uebung05/logistics/material/ShellBatches.java +++ b/src/uebung05/logistics/material/ShellBatches.java @@ -1,25 +1,58 @@ -package uebung05.logistics.material; +package logistics.material; -import uebung05.logistics.quantities.IntUnit; +import logistics.quantities.IntUnit; -public class ShellBatches implements IntUnit{ - private static ShellBatches instance; - private int amount; +/** + * The ShellBatches class represents a unit of measurement for 120mm shell batches. + * It is a singleton class, meaning only one instance of the class can exist at a time. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class ShellBatches implements IntUnit { - private ShellBatches(int amount){ - this.amount = amount; + private static ShellBatches INSTANCE; + + private ShellBatches() {} + + /** + * Get the singleton instance of the ShellBatches class + * + * @return The singleton instance of the ShellBatches class + */ + public static ShellBatches getINSTANCE() { + if (INSTANCE == null) { + INSTANCE = new ShellBatches(); + } + return INSTANCE; } + /** + * Get a string representation of the ShellBatches object + * + * @return A string representation of the ShellBatches object + */ @Override public String toString() { - return amount + " batches of 120mm shells"; + return "batches of 120mm shells"; } - public static ShellBatches getInstance(int amount){ - if (instance == null){ - instance = new ShellBatches(amount); - } - return instance; + /** + * Set the integer value of the ShellBatches object + * + * @param value The integer value to set + */ + public void setValue(int value) { + // Implementation goes here } -} + /** + * Get the integer value of the ShellBatches object + * + * @return The integer value of the ShellBatches object + */ + public int getValue() { + // Implementation goes here + return 0; + } +} \ No newline at end of file diff --git a/src/uebung05/logistics/quantities/FloatUnit.java b/src/uebung05/logistics/quantities/FloatUnit.java old mode 100644 new mode 100755 index d9321a7..69d5cf3 --- a/src/uebung05/logistics/quantities/FloatUnit.java +++ b/src/uebung05/logistics/quantities/FloatUnit.java @@ -1,5 +1,7 @@ -package uebung05.logistics.quantities; +package logistics.quantities; +/** + * @author Nikolaus Köberlein + */ public interface FloatUnit { - } diff --git a/src/uebung05/logistics/quantities/IntUnit.java b/src/uebung05/logistics/quantities/IntUnit.java old mode 100644 new mode 100755 index b04d6e8..1b6ed1f --- a/src/uebung05/logistics/quantities/IntUnit.java +++ b/src/uebung05/logistics/quantities/IntUnit.java @@ -1,5 +1,7 @@ -package uebung05.logistics.quantities; - -public interface IntUnit { +package logistics.quantities; +/** + * @author Nikolaus Köberlein + */ +public interface IntUnit extends Unit { } diff --git a/src/uebung05/logistics/quantities/NeedCollector.java b/src/uebung05/logistics/quantities/NeedCollector.java new file mode 100755 index 0000000..00b0597 --- /dev/null +++ b/src/uebung05/logistics/quantities/NeedCollector.java @@ -0,0 +1,108 @@ +package logistics.quantities; + +import logistics.material.BulletBelts; +import logistics.material.Grease; +import logistics.material.LiterDiesel; +import logistics.material.MetGallonsKerosene; +import logistics.material.Oil; +import logistics.material.RocketPods; +import logistics.material.ShellBatches; + +import java.util.HashMap; +import java.util.Map; + +/** + * The NeedCollector class is responsible for storing and managing the needed supplies for vehicles. + * It contains two maps, intNeeded and floatNeeded, to store the needed supplies. + * Users can add an integer or float amount of a specific unit to the maps using the add method. + * The getNeed method can be used to retrieve the integer or float amount needed for a specific unit. + * The show method prints the needed supplies for all vehicles. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class NeedCollector { + + // Maps to store the needed supplies for vehicles + private Map intNeeded; + private Map floatNeeded; + + /** + * Initialize the two maps for storing the needed supplies + */ + public NeedCollector() { + intNeeded = new HashMap<>(); + floatNeeded = new HashMap<>(); + } + + /** + * Add an integer amount of a specific IntUnit to the intNeeded map + * + * @param amount The integer amount to be added + * @param unit The IntUnit to which the amount belongs + */ + public void add(int amount, IntUnit unit) { + intNeeded.merge(unit, amount, Integer::sum); + } + + /** + * Add a float amount of a specific FloatUnit to the floatNeeded map + * + * @param amount The float amount to be added + * @param unit The FloatUnit to which the amount belongs + */ + public void add(float amount, FloatUnit unit) { + floatNeeded.merge(unit, amount, Float::sum); + } + + /** + * Get the integer amount needed for a specific IntUnit + * + * @param unit The IntUnit for which the amount is needed + * @return The integer amount needed for the specified unit + */ + public int getNeed(IntUnit unit) { + return intNeeded.getOrDefault(unit, 0); + } + + /** + * Get the float amount needed for a specific FloatUnit + * + * @param unit The FloatUnit for which the amount is needed + * @return The float amount needed for the specified unit + */ + public float getNeed(FloatUnit unit) { + return floatNeeded.getOrDefault(unit, 0.0f); + } + + /** + * Print the needed supplies for all vehicles + */ + public void show() { + System.out.println("Needed supplies for all vehicles:"); + + // Print the needed supplies for specific units + System.out.println("- " + getNeed(Grease.getINSTANCE()) + " " + Grease.getINSTANCE()); + System.out.println("- " + getNeed(ShellBatches.getINSTANCE()) + " " + ShellBatches.getINSTANCE()); + System.out.println("- " + getNeed(RocketPods.getINSTANCE()) + " " + RocketPods.getINSTANCE()); + System.out.println("- " + getNeed(BulletBelts.getINSTANCE()) + " " + BulletBelts.getINSTANCE()); + System.out.println("- " + getNeed(Oil.getINSTANCE()) + " " + Oil.getINSTANCE()); + System.out.println("- " + getNeed(MetGallonsKerosene.getINSTANCE()) + " " + MetGallonsKerosene.getINSTANCE()); + System.out.println("- " + getNeed(LiterDiesel.getINSTANCE()) + " " + LiterDiesel.getINSTANCE()); + + //todo + /* + for (Map.Entry entry : collector.getIntNeeded().entrySet()) { + IntUnit unit = entry.getKey(); + int amount = entry.getValue(); + + } + + for (FloatUnit unit : FloatUnit.getAllUnits()) { + float totalNeed = collector.getNeed(unit); + System.out.println("- " + totalNeed + " " + unit.toString()); + }*/ + System.out.println(); + } + +} \ No newline at end of file diff --git a/src/uebung05/logistics/quantities/Unit.java b/src/uebung05/logistics/quantities/Unit.java new file mode 100755 index 0000000..258b194 --- /dev/null +++ b/src/uebung05/logistics/quantities/Unit.java @@ -0,0 +1,7 @@ +package logistics.quantities; + +/** + * @author Nikolaus Köberlein + */ +public interface Unit { +} diff --git a/src/uebung05/logistics/storage/FloatStorage.java b/src/uebung05/logistics/storage/FloatStorage.java old mode 100644 new mode 100755 index dce9b10..bc14d22 --- a/src/uebung05/logistics/storage/FloatStorage.java +++ b/src/uebung05/logistics/storage/FloatStorage.java @@ -1,60 +1,134 @@ -package uebung05.logistics.storage; +package logistics.storage; -import uebung05.logistics.NeedCollector; -import uebung05.logistics.quantities.FloatUnit; +import logistics.quantities.FloatUnit; +import logistics.quantities.NeedCollector; -public class FloatStorage implements FloatUnit{ +/** + * The FloatStorage class represents a floating-point storage for a specific FloatUnit object. + * It includes methods for getting the unit, stored amount, and maximum capacity, as well as + * methods for consuming, filling, and reporting needs. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class FloatStorage { + private FloatUnit unit; private float stored; - private final FloatUnit unit; - private final float max; + private float max; - public FloatStorage(float stored, FloatUnit unit, float max){ - this.stored = stored; - this.unit = unit; - this.max = max; - } - - public float getStored(){ - return stored; - } - - public FloatUnit getUnit(){ - return unit; - } - - public float getMax(){ - return max; - } - - @Override - public String toString() { - return "storage with "+ stored + " of " + max + " units of " + unit; - } - - public float consume(float amount){ - - float actualConsumed = Math.min(stored, amount); - - stored = stored - actualConsumed; - - return actualConsumed; - } - - public void fill(float amount){ - if (stored+amount > max) { - stored = max; + /** + * Construct a FloatStorage object with a stored amount, FloatUnit object, and maximum capacity + * + * @param stored The initial stored amount for the FloatStorage object + * @param unit The FloatUnit object for the FloatStorage object + * @param max The maximum capacity for the FloatStorage object + * + * @throws java.lang.IllegalArgumentException if unit is negative + */ + public FloatStorage(float stored, FloatUnit unit, float max) { + if (stored < 0 || max < 0) { + throw new IllegalArgumentException("Units cannot be negative"); + } + if (stored > max) { + this.stored = max; + this.unit = unit; + this.max = max; } else { - stored = stored + amount; + this.stored = stored; + this.unit = unit; + this.max = max; } } - public void fillUp(){ + /** + * Get the FloatUnit object for the FloatStorage object + * + * @return The FloatUnit object for the FloatStorage object + */ + public FloatUnit getUnit() { + return unit; + } + + /** + * Get the stored amount for the FloatStorage object + * + * @return The stored amount for the FloatStorage object + */ + public float getStored() { + return stored; + } + + /** + * Get the maximum capacity for the FloatStorage object + * + * @return The maximum capacity for the FloatStorage object + */ + public float getMax() { + return max; + } + + /** + * Consume a specific amount from the FloatStorage object + * + * @param amount The amount to consume from the FloatStorage object + * @return The amount consumed from the FloatStorage object + * + * @throws java.lang.IllegalArgumentException if consume is negative + */ + public float consume(float amount) { + if (amount < 0) { + throw new IllegalArgumentException("Consume cannot be negative"); + } + if (stored < amount) { + float newStored = stored; + stored = 0; + return newStored; + } + stored -= amount; + return amount; + } + + /** + * Fill the FloatStorage object with a specific amount + * + * @param amount The amount to fill the FloatStorage object with + * + * @throws java.lang.IllegalArgumentException if consume is negative + */ + public void fill(float amount) { + if (amount < 0) { + throw new IllegalArgumentException("Consume cannot be negative"); + } + stored += amount; + if (max < stored) { + fillUp(); + } + } + + /** + * Fill the FloatStorage object to its maximum capacity + */ + public void fillUp() { stored = max; } - public void reportNeed(NeedCollector collector){ + /** + * Report the needs of the FloatStorage object to a NeedCollector object + * + * @param collector The NeedCollector object to which to report the needs + */ + public void reportNeed (NeedCollector collector) { collector.add(max-stored, unit); } -} + /** + * Get a string representation of the FloatStorage object + * + * @return A string representation of the FloatStorage object + */ + @Override + public String toString() { + return "storage with " + stored + " of " + max + " " + unit; + } +} \ No newline at end of file diff --git a/src/uebung05/logistics/storage/IntStorage.java b/src/uebung05/logistics/storage/IntStorage.java old mode 100644 new mode 100755 index 44e00c1..c1c5b12 --- a/src/uebung05/logistics/storage/IntStorage.java +++ b/src/uebung05/logistics/storage/IntStorage.java @@ -1,58 +1,134 @@ -package uebung05.logistics.storage; +package logistics.storage; -import uebung05.logistics.NeedCollector; -import uebung05.logistics.quantities.IntUnit; +import logistics.quantities.IntUnit; +import logistics.quantities.NeedCollector; -public class IntStorage implements IntUnit { +/** + * The IntStorage class represents an integer storage for a specific IntUnit object. + * It includes methods for getting the unit, stored amount, and maximum capacity, as + * well as methods for consuming, filling, and reporting needs. + * + * @author Nikolaus Köberlein + * @version 1.0 + */ +public class IntStorage { + + private IntUnit unit; private int stored; - private final IntUnit unit; - private final int max; + private int max; - public IntStorage(int stored, IntUnit unit, int max){ - this.stored = stored; - this.unit = unit; - this.max = max; - } - - public int getStored(){ - return stored; - } - - public IntUnit getUnit(){ - return unit; - } - - public int getMax(){ - return max; - } - - @Override - public String toString() { - return "storage with "+ stored + " of " + max + " units of " + unit; - } - - public int consume(int amount){ - - int actualConsumed = Math.min(stored, amount); - - stored = stored - actualConsumed; - - return actualConsumed; - } - - public void fill(int amount){ - if (stored+amount > max) { - stored = max; + /** + * Construct an IntStorage object with a stored amount, IntUnit object, and maximum capacity + * + * @param stored The initial stored amount for the IntStorage object + * @param unit The IntUnit object for the IntStorage object + * @param max The maximum capacity for the IntStorage object + * + * @throws java.lang.IllegalArgumentException if unit is negative + */ + public IntStorage(int stored, IntUnit unit, int max) { + if (stored < 0 || max < 0) { + throw new IllegalArgumentException("Units cannot be negative"); + } + if (stored > max) { + this.stored = max; + this.unit = unit; + this.max = max; } else { - stored = stored + amount; + this.stored = stored; + this.unit = unit; + this.max = max; } } - public void fillUp(){ + /** + * Get the IntUnit object for the IntStorage object + * + * @return The IntUnit object for the IntStorage object + */ + public IntUnit getUnit() { + return unit; + } + + /** + * Get the stored amount for the IntStorage object + * + * @return The stored amount for the IntStorage object + */ + public int getStored() { + return stored; + } + + /** + * Get the maximum capacity for the IntStorage object + * + * @return The maximum capacity for the IntStorage object + */ + public int getMax() { + return max; + } + + /** + * Consume a specific amount from the IntStorage object + * + * @param amount The amount to consume from the IntStorage object + * @return The amount consumed from the IntStorage object + * + * @throws java.lang.IllegalArgumentException if consume is negative + */ + public int consume(int amount) { + if (amount < 0) { + throw new IllegalArgumentException("Consume cannot be negative"); + } + if (stored < amount) { + int newStored = stored; + stored = 0; + return newStored; + } + stored -= amount; + return amount; + } + + /** + * Fill the IntStorage object with a specific amount + * + * @param amount The amount to fill the IntStorage object with + * + * @throws java.lang.IllegalArgumentException if consume is negative + */ + public void fill(int amount) { + if (amount < 0) { + throw new IllegalArgumentException("Consume cannot be negative"); + } + stored += amount; + if (max < stored) { + fillUp(); + } + } + + /** + * Fill the IntStorage object to its maximum capacity + */ + public void fillUp() { stored = max; } - public void reportNeed(NeedCollector collector){ + /** + * Report the needs of the IntStorage object to a NeedCollector object + * + * @param collector The NeedCollector object to which to report the needs + */ + public void reportNeed (NeedCollector collector) { collector.add(max-stored, unit); } -} + + /** + * Get a string representation of the IntStorage object + * + * @return A string representation of the IntStorage object + */ + @Override + public String toString() { + return "storage with " + stored + " of " + max + " " + unit; + } +} \ No newline at end of file From a84a407c31e8c34d97d8c3d5ee874dcd4a348b8a Mon Sep 17 00:00:00 2001 From: peet Date: Tue, 21 May 2024 16:34:54 +0000 Subject: [PATCH 2/2] changed Storage to implement Unit --- src/uebung05/logistics/storage/FloatStorage.java | 6 +++--- src/uebung05/logistics/storage/IntStorage.java | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/uebung05/logistics/storage/FloatStorage.java b/src/uebung05/logistics/storage/FloatStorage.java index bc14d22..9c42a30 100755 --- a/src/uebung05/logistics/storage/FloatStorage.java +++ b/src/uebung05/logistics/storage/FloatStorage.java @@ -11,11 +11,11 @@ import logistics.quantities.NeedCollector; * @author Nikolaus Köberlein * @version 1.0 */ -public class FloatStorage { +public class FloatStorage implements FloatUnit { - private FloatUnit unit; + private final FloatUnit unit; private float stored; - private float max; + private final float max; /** * Construct a FloatStorage object with a stored amount, FloatUnit object, and maximum capacity diff --git a/src/uebung05/logistics/storage/IntStorage.java b/src/uebung05/logistics/storage/IntStorage.java index c1c5b12..0092f91 100755 --- a/src/uebung05/logistics/storage/IntStorage.java +++ b/src/uebung05/logistics/storage/IntStorage.java @@ -11,11 +11,11 @@ import logistics.quantities.NeedCollector; * @author Nikolaus Köberlein * @version 1.0 */ -public class IntStorage { +public class IntStorage implements IntUnit { - private IntUnit unit; + private final IntUnit unit; private int stored; - private int max; + private final int max; /** * Construct an IntStorage object with a stored amount, IntUnit object, and maximum capacity @@ -94,11 +94,11 @@ public class IntStorage { * * @param amount The amount to fill the IntStorage object with * - * @throws java.lang.IllegalArgumentException if consume is negative + * @throws java.lang.IllegalArgumentException if amount is negative */ public void fill(int amount) { if (amount < 0) { - throw new IllegalArgumentException("Consume cannot be negative"); + throw new IllegalArgumentException("Filled amount cannot be negative"); } stored += amount; if (max < stored) {