diff --git a/bin/uebung05/logistics/Demo.class b/bin/uebung05/logistics/Demo.class new file mode 100644 index 0000000..934e55a Binary files /dev/null and b/bin/uebung05/logistics/Demo.class differ diff --git a/bin/uebung05/logistics/Helicopter.class b/bin/uebung05/logistics/Helicopter.class new file mode 100644 index 0000000..53851ae Binary files /dev/null and b/bin/uebung05/logistics/Helicopter.class differ diff --git a/bin/uebung05/logistics/NeedCollector.class b/bin/uebung05/logistics/NeedCollector.class new file mode 100644 index 0000000..2a0313d Binary files /dev/null and b/bin/uebung05/logistics/NeedCollector.class differ diff --git a/bin/uebung05/logistics/Tank.class b/bin/uebung05/logistics/Tank.class new file mode 100644 index 0000000..b8c08ef Binary files /dev/null and b/bin/uebung05/logistics/Tank.class differ diff --git a/bin/uebung05/logistics/Truck.class b/bin/uebung05/logistics/Truck.class new file mode 100644 index 0000000..f70bde5 Binary files /dev/null and b/bin/uebung05/logistics/Truck.class differ diff --git a/bin/uebung05/logistics/Vehicle.class b/bin/uebung05/logistics/Vehicle.class new file mode 100644 index 0000000..e42bb66 Binary files /dev/null and b/bin/uebung05/logistics/Vehicle.class differ diff --git a/bin/uebung05/logistics/material/BulletBelts.class b/bin/uebung05/logistics/material/BulletBelts.class new file mode 100644 index 0000000..c8f26cc Binary files /dev/null and b/bin/uebung05/logistics/material/BulletBelts.class differ diff --git a/bin/uebung05/logistics/material/Grease.class b/bin/uebung05/logistics/material/Grease.class new file mode 100644 index 0000000..d8dbd3d Binary files /dev/null and b/bin/uebung05/logistics/material/Grease.class differ diff --git a/bin/uebung05/logistics/material/LiterDiesel.class b/bin/uebung05/logistics/material/LiterDiesel.class new file mode 100644 index 0000000..b2b9666 Binary files /dev/null and b/bin/uebung05/logistics/material/LiterDiesel.class differ diff --git a/bin/uebung05/logistics/material/MetGallonsKerosene.class b/bin/uebung05/logistics/material/MetGallonsKerosene.class new file mode 100644 index 0000000..8240555 Binary files /dev/null and b/bin/uebung05/logistics/material/MetGallonsKerosene.class differ diff --git a/bin/uebung05/logistics/material/Oil.class b/bin/uebung05/logistics/material/Oil.class new file mode 100644 index 0000000..50a9057 Binary files /dev/null and b/bin/uebung05/logistics/material/Oil.class differ diff --git a/bin/uebung05/logistics/material/RocketPods.class b/bin/uebung05/logistics/material/RocketPods.class new file mode 100644 index 0000000..12572e2 Binary files /dev/null and b/bin/uebung05/logistics/material/RocketPods.class differ diff --git a/bin/uebung05/logistics/material/ShellBatches.class b/bin/uebung05/logistics/material/ShellBatches.class new file mode 100644 index 0000000..c659f0a Binary files /dev/null and b/bin/uebung05/logistics/material/ShellBatches.class differ diff --git a/bin/uebung05/logistics/quantities/FloatUnit.class b/bin/uebung05/logistics/quantities/FloatUnit.class new file mode 100644 index 0000000..5847b25 Binary files /dev/null and b/bin/uebung05/logistics/quantities/FloatUnit.class differ diff --git a/bin/uebung05/logistics/quantities/IntUnit.class b/bin/uebung05/logistics/quantities/IntUnit.class new file mode 100644 index 0000000..e32e6f3 Binary files /dev/null and b/bin/uebung05/logistics/quantities/IntUnit.class differ diff --git a/bin/uebung05/logistics/storage/FloatStorage.class b/bin/uebung05/logistics/storage/FloatStorage.class new file mode 100644 index 0000000..782ade7 Binary files /dev/null and b/bin/uebung05/logistics/storage/FloatStorage.class differ diff --git a/bin/uebung05/logistics/storage/IntStorage.class b/bin/uebung05/logistics/storage/IntStorage.class new file mode 100644 index 0000000..d834f4a Binary files /dev/null and b/bin/uebung05/logistics/storage/IntStorage.class differ diff --git a/src/uebung05/logistics/Demo.java b/src/uebung05/logistics/Demo.java new file mode 100644 index 0000000..beded21 --- /dev/null +++ b/src/uebung05/logistics/Demo.java @@ -0,0 +1,9 @@ +package uebung05.logistics; + +public class Demo { + + public static void main(String[] args) { + + } + +} diff --git a/src/uebung05/logistics/Helicopter.java b/src/uebung05/logistics/Helicopter.java new file mode 100644 index 0000000..b8b56bf --- /dev/null +++ b/src/uebung05/logistics/Helicopter.java @@ -0,0 +1,5 @@ +package uebung05.logistics; + +public class Helicopter extends Vehicle{ + +} diff --git a/src/uebung05/logistics/NeedCollector.java b/src/uebung05/logistics/NeedCollector.java new file mode 100644 index 0000000..7294621 --- /dev/null +++ b/src/uebung05/logistics/NeedCollector.java @@ -0,0 +1,60 @@ +package uebung05.logistics; + +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) { + + } + + /** + * 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; + } + + /** + * 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; + } + + /** + * Prints the total requirements in the therminal + * + */ + public void show(){ + + } +} \ No newline at end of file diff --git a/src/uebung05/logistics/Tank.java b/src/uebung05/logistics/Tank.java new file mode 100644 index 0000000..c6a2d79 --- /dev/null +++ b/src/uebung05/logistics/Tank.java @@ -0,0 +1,5 @@ +package uebung05.logistics; + +public class Tank extends Vehicle{ + +} diff --git a/src/uebung05/logistics/Truck.java b/src/uebung05/logistics/Truck.java new file mode 100644 index 0000000..eaf8d62 --- /dev/null +++ b/src/uebung05/logistics/Truck.java @@ -0,0 +1,17 @@ +package uebung05.logistics; + +import java.util.HashMap; +import java.util.Map; + +import uebung05.logistics.material.Oil; +import uebung05.logistics.quantities.IntUnit; + +public class Truck extends Vehicle { + + public Truck(String name){ + this.name = name; + materials = new HashMap<>(); + materials.put(Oil.getInstance(0), 5); + } + +} diff --git a/src/uebung05/logistics/Vehicle.java b/src/uebung05/logistics/Vehicle.java new file mode 100644 index 0000000..c285514 --- /dev/null +++ b/src/uebung05/logistics/Vehicle.java @@ -0,0 +1,16 @@ +package uebung05.logistics; + +import java.util.Map; + +import uebung05.logistics.quantities.IntUnit; + +public abstract class Vehicle{ + protected String name; + protected Map materials; + + protected abstract void reportNeeds(NeedCollector collector); + + protected abstract void fillUpAll(); + + protected abstract void consumeAll(int intensityRate); +} diff --git a/src/uebung05/logistics/material/BulletBelts.java b/src/uebung05/logistics/material/BulletBelts.java new file mode 100644 index 0000000..d44dc5c --- /dev/null +++ b/src/uebung05/logistics/material/BulletBelts.java @@ -0,0 +1,24 @@ +package uebung05.logistics.material; + +import uebung05.logistics.quantities.IntUnit; + +public class BulletBelts implements IntUnit{ + private static BulletBelts instance; + private int amount; + + private BulletBelts(int amount){ + this.amount = amount; + } + + @Override + public String toString() { + return amount + " belts of 7.62 bullets"; + } + + public static BulletBelts getInstance(int amount){ + if (instance == null){ + instance = new BulletBelts(amount); + } + return instance; + } +} diff --git a/src/uebung05/logistics/material/Grease.java b/src/uebung05/logistics/material/Grease.java new file mode 100644 index 0000000..4584cf2 --- /dev/null +++ b/src/uebung05/logistics/material/Grease.java @@ -0,0 +1,25 @@ +package uebung05.logistics.material; + +import uebung05.logistics.quantities.IntUnit; + +public class Grease implements IntUnit{ + private static Grease instance; + private int amount; + + private Grease(int amount){ + this.amount = amount; + } + + @Override + public String toString() { + return amount + " units of grease"; + } + + public static Grease getInstance(int amount){ + if (instance == null){ + instance = new Grease(amount); + } + return instance; + } + +} diff --git a/src/uebung05/logistics/material/LiterDiesel.java b/src/uebung05/logistics/material/LiterDiesel.java new file mode 100644 index 0000000..63184af --- /dev/null +++ b/src/uebung05/logistics/material/LiterDiesel.java @@ -0,0 +1,25 @@ +package uebung05.logistics.material; + +import uebung05.logistics.quantities.FloatUnit; + +public class LiterDiesel implements FloatUnit{ + private static LiterDiesel instance; + private float amount; + + private LiterDiesel(float amount){ + this.amount = amount; + } + + @Override + public String toString() { + return amount + " liters of diesel"; + } + + public static LiterDiesel getInstance(float amount){ + if (instance == null){ + instance = new LiterDiesel(amount); + } + return instance; + } + +} diff --git a/src/uebung05/logistics/material/MetGallonsKerosene.java b/src/uebung05/logistics/material/MetGallonsKerosene.java new file mode 100644 index 0000000..a9c2d3a --- /dev/null +++ b/src/uebung05/logistics/material/MetGallonsKerosene.java @@ -0,0 +1,25 @@ +package uebung05.logistics.material; + +import uebung05.logistics.quantities.FloatUnit; + +public class MetGallonsKerosene implements FloatUnit{ + private static MetGallonsKerosene instance; + private float amount; + + private MetGallonsKerosene(float amount){ + this.amount = amount; + } + + @Override + public String toString() { + return amount + " met gallons of kerosene"; + } + + public static MetGallonsKerosene getInstance(float amount){ + if (instance == null){ + instance = new MetGallonsKerosene(amount); + } + return instance; + } + +} diff --git a/src/uebung05/logistics/material/Oil.java b/src/uebung05/logistics/material/Oil.java new file mode 100644 index 0000000..acb4cd4 --- /dev/null +++ b/src/uebung05/logistics/material/Oil.java @@ -0,0 +1,24 @@ +package uebung05.logistics.material; + +import uebung05.logistics.quantities.IntUnit; + +public class Oil implements IntUnit{ + private static Oil instance; + private int amount; + + private Oil(int amount){ + this.amount = amount; + } + + @Override + public String toString() { + return amount + " units of oil"; + } + + public static Oil getInstance(int amount){ + if (instance == null){ + instance = new Oil(amount); + } + return instance; + } +} diff --git a/src/uebung05/logistics/material/RocketPods.java b/src/uebung05/logistics/material/RocketPods.java new file mode 100644 index 0000000..229f1db --- /dev/null +++ b/src/uebung05/logistics/material/RocketPods.java @@ -0,0 +1,24 @@ +package uebung05.logistics.material; + +import uebung05.logistics.quantities.IntUnit; + +public class RocketPods implements IntUnit{ + private static RocketPods instance; + private int amount; + + private RocketPods(int amount){ + this.amount = amount; + } + + @Override + public String toString() { + return amount + " pods of 70mm rockets"; + } + + public static RocketPods getInstance(int amount){ + if (instance == null){ + instance = new RocketPods(amount); + } + return instance; + } +} diff --git a/src/uebung05/logistics/material/ShellBatches.java b/src/uebung05/logistics/material/ShellBatches.java new file mode 100644 index 0000000..d411659 --- /dev/null +++ b/src/uebung05/logistics/material/ShellBatches.java @@ -0,0 +1,25 @@ +package uebung05.logistics.material; + +import uebung05.logistics.quantities.IntUnit; + +public class ShellBatches implements IntUnit{ + private static ShellBatches instance; + private int amount; + + private ShellBatches(int amount){ + this.amount = amount; + } + + @Override + public String toString() { + return amount + " batches of 120mm shells"; + } + + public static ShellBatches getInstance(int amount){ + if (instance == null){ + instance = new ShellBatches(amount); + } + return instance; + } + +} diff --git a/src/uebung05/logistics/quantities/FloatUnit.java b/src/uebung05/logistics/quantities/FloatUnit.java new file mode 100644 index 0000000..d9321a7 --- /dev/null +++ b/src/uebung05/logistics/quantities/FloatUnit.java @@ -0,0 +1,5 @@ +package uebung05.logistics.quantities; + +public interface FloatUnit { + +} diff --git a/src/uebung05/logistics/quantities/IntUnit.java b/src/uebung05/logistics/quantities/IntUnit.java new file mode 100644 index 0000000..b04d6e8 --- /dev/null +++ b/src/uebung05/logistics/quantities/IntUnit.java @@ -0,0 +1,5 @@ +package uebung05.logistics.quantities; + +public interface IntUnit { + +} diff --git a/src/uebung05/logistics/storage/FloatStorage.java b/src/uebung05/logistics/storage/FloatStorage.java new file mode 100644 index 0000000..dce9b10 --- /dev/null +++ b/src/uebung05/logistics/storage/FloatStorage.java @@ -0,0 +1,60 @@ +package uebung05.logistics.storage; + +import uebung05.logistics.NeedCollector; +import uebung05.logistics.quantities.FloatUnit; + +public class FloatStorage implements FloatUnit{ + + private float stored; + private final FloatUnit unit; + private final 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; + } else { + stored = stored + amount; + } + } + + public void fillUp(){ + stored = max; + } + + public void reportNeed(NeedCollector collector){ + collector.add(max-stored, unit); + } + +} diff --git a/src/uebung05/logistics/storage/IntStorage.java b/src/uebung05/logistics/storage/IntStorage.java new file mode 100644 index 0000000..44e00c1 --- /dev/null +++ b/src/uebung05/logistics/storage/IntStorage.java @@ -0,0 +1,58 @@ +package uebung05.logistics.storage; + +import uebung05.logistics.NeedCollector; +import uebung05.logistics.quantities.IntUnit; + +public class IntStorage implements IntUnit { + private int stored; + private final IntUnit unit; + private final 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; + } else { + stored = stored + amount; + } + } + + public void fillUp(){ + stored = max; + } + + public void reportNeed(NeedCollector collector){ + collector.add(max-stored, unit); + } +} diff --git a/test/uebung/uebung05/logistics/ManagerTest.java b/test/uebung/uebung05/logistics/ManagerTest.java new file mode 100644 index 0000000..0eb3a56 --- /dev/null +++ b/test/uebung/uebung05/logistics/ManagerTest.java @@ -0,0 +1,67 @@ +package logistics; + +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 logistics.quantities.NeedCollector; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ManagerTest { + private static final float EPS = 1e-5f; + private Manager manager; + + @Before + public void setup() { + manager = new Manager(); + manager.addVehicle(new Tank("Leo1")); + manager.addVehicle(new Tank("Leo2")); + manager.addVehicle(new Helicopter("Tiger1")); + manager.addVehicle(new Helicopter("Tiger2")); + } + + @Test + public void testInitialNeed() { + final NeedCollector collector = manager.collectNeeds(); + assertEquals(4, collector.getNeed(RocketPods.INSTANCE)); + assertEquals(12, collector.getNeed(Oil.INSTANCE)); + assertEquals(24, collector.getNeed(BulletBelts.INSTANCE)); + assertEquals(20, collector.getNeed(ShellBatches.INSTANCE)); + assertEquals(12, collector.getNeed(Grease.INSTANCE)); + assertEquals(1000f, collector.getNeed(MetGallonsKerosene.INSTANCE), EPS); + assertEquals(2400f, collector.getNeed(LiterDiesel.INSTANCE), EPS); + } + + @Test + public void testNeedAfterFillUp() { + manager.fillUpVehicles(); + final NeedCollector collector = manager.collectNeeds(); + assertEquals(0, collector.getNeed(RocketPods.INSTANCE)); + assertEquals(0, collector.getNeed(Oil.INSTANCE)); + assertEquals(0, collector.getNeed(BulletBelts.INSTANCE)); + assertEquals(0, collector.getNeed(ShellBatches.INSTANCE)); + assertEquals(0, collector.getNeed(Grease.INSTANCE)); + assertEquals(0f, collector.getNeed(MetGallonsKerosene.INSTANCE), EPS); + assertEquals(0f, collector.getNeed(LiterDiesel.INSTANCE), EPS); + } + + @Test + public void testNeedAfterLogTick() { + manager.fillUpVehicles(); + manager.logTick(1); + final NeedCollector collector = manager.collectNeeds(); + assertEquals(2, collector.getNeed(RocketPods.INSTANCE)); + assertEquals(4, collector.getNeed(Oil.INSTANCE)); + assertEquals(6, collector.getNeed(BulletBelts.INSTANCE)); + assertEquals(4, collector.getNeed(ShellBatches.INSTANCE)); + assertEquals(4, collector.getNeed(Grease.INSTANCE)); + assertEquals(100f, collector.getNeed(MetGallonsKerosene.INSTANCE), EPS); + assertEquals(360f, collector.getNeed(LiterDiesel.INSTANCE), EPS); + } +} diff --git a/test/uebung/uebung05/logistics/storage/IntStorageTest.java b/test/uebung/uebung05/logistics/storage/IntStorageTest.java new file mode 100644 index 0000000..bc086ac --- /dev/null +++ b/test/uebung/uebung05/logistics/storage/IntStorageTest.java @@ -0,0 +1,80 @@ +package logistics.storage; + +import logistics.material.Oil; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class IntStorageTest { + private static final int MAX = 3; + + private IntStorage intStorage; + + @Before + public void setup() { + intStorage = new IntStorage(0, Oil.INSTANCE, MAX); + } + + @Test + public void testEmptyStorage() { + assertEquals(0, intStorage.getStored()); + } + + @Test + public void testGetStorage() { + intStorage.fill(1); + assertEquals(1, intStorage.getStored()); + } + + @Test + public void testGetMax() { + assertEquals(MAX, intStorage.getMax()); + } + + @Test + public void testFillUp() { + intStorage.fillUp(); + assertEquals(MAX, intStorage.getStored()); + } + + @Test + public void testUpperBound() { + intStorage.fill(MAX + 1); + assertEquals(MAX, intStorage.getStored()); + } + + @Test + public void testConsume() { + intStorage.fillUp(); + assertEquals(MAX, intStorage.getStored()); + assertEquals(MAX, intStorage.consume(MAX)); + } + + @Test + public void testLowerBound() { + intStorage.consume(1); + assertEquals(0, intStorage.getStored()); + } + + @Test(expected = IllegalArgumentException.class) + public void testIllegalFill() { + intStorage.fill(-1); + } + + @Test(expected = IllegalArgumentException.class) + public void testIllegalConsume() { + intStorage.consume(-1); + } + + @Test(expected = IllegalArgumentException.class) + public void testIllegalLowerBoundConstructor() { + new IntStorage(-1, Oil.INSTANCE, MAX); + } + + @Test + public void testUpperBoundConstructor() { + final IntStorage storage = new IntStorage(MAX + 1, Oil.INSTANCE, MAX); + assertEquals(MAX, storage.getStored()); + } +}