Compare commits

...

31 Commits

Author SHA1 Message Date
5f15f03d92 small change 2024-09-14 17:41:40 +00:00
9908656813 finished uebung10 2024-06-18 13:17:01 +00:00
b439030fee Ich hasse Minas 2024-06-18 12:55:21 +00:00
7fea13b9b3 MINAS??? 2024-06-17 22:33:20 +02:00
639da57def MINAS 2024-06-17 22:33:01 +02:00
0c95c28bc4 testing 2024-06-15 23:30:02 +02:00
ac1cc19a88 finished uebung09 2024-06-15 16:20:39 +02:00
62da4a9ea5 ahhhhhhhhh 2024-06-14 12:01:59 +02:00
dad5a33695 implemented hasnext 2024-06-14 08:08:10 +00:00
93fb940a8c refactor 2024-06-14 01:13:30 +02:00
55e6561e02 ich komm nicht mehr weiter 2024-06-14 01:12:27 +02:00
7972c9088c refactor 2024-06-14 01:03:45 +02:00
e59cbb88f1 refactored testing 2024-06-14 00:33:41 +02:00
440eed0e9d started on b 2024-06-13 18:15:48 +00:00
49262c4954 refactor 2024-06-13 15:02:04 +00:00
fa85372c13 initial commit 2024-06-13 15:37:45 +02:00
8c224faa0e implemented ToTextVisitor 2024-06-08 22:04:10 +02:00
85e8396ce9 finished TableofContents 2024-06-08 19:49:45 +00:00
81ea768dca finished CountWordsVisitor 2024-06-08 12:53:20 +00:00
dcf2a95b4f implemented accept and visit 2024-06-08 12:14:16 +00:00
e518460e81 started on visitor pattern 2024-06-07 15:25:26 +02:00
753d5e2780 implemented composite pattern 2024-06-07 15:25:15 +02:00
41743095bd i dont like it 2024-06-06 17:41:33 +02:00
38287f8c0b initial commit 2024-06-06 17:27:35 +02:00
d9eaae7b7a build 2024-06-05 00:11:56 +02:00
b90d94bf41 Merge branch 'main' of https://git.sfs.ddnss.org/peet/oop 2024-06-05 00:11:37 +02:00
096a49e0a8 implemented ue06 2024-06-05 00:11:35 +02:00
a84a407c31 changed Storage to implement Unit 2024-05-21 16:34:54 +00:00
c60c85ade0 updated uebung05 from lsg 2024-05-21 14:18:10 +00:00
a021a64624 Merge branch 'main' of https://git.sfs.ddnss.org/peet/oop 2024-05-16 18:07:21 +02:00
65da2599bd meh 2024-05-16 18:07:20 +02:00
155 changed files with 3494 additions and 4731 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bin/uebung06/Field.class Normal file

Binary file not shown.

BIN
bin/uebung06/Sudoku.class Normal file

Binary file not shown.

Binary file not shown.

BIN
bin/uebung06/VALUE.class Normal file

Binary file not shown.

BIN
bin/uebung08/doc/Book.class Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bin/uebung10/logo/Go.class Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,72 @@
package test.uebung.uebung05.logistics;
import uebung05.logistics.Helicopter;
import uebung05.logistics.Manager;
import uebung05.logistics.Tank;
import uebung05.logistics.material.BulletBelts;
import uebung05.logistics.material.Grease;
import uebung05.logistics.material.LiterDiesel;
import uebung05.logistics.material.MetGallonsKerosene;
import uebung05.logistics.material.Oil;
import uebung05.logistics.material.RocketPods;
import uebung05.logistics.material.ShellBatches;
import uebung05.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);
}
}

View File

@@ -0,0 +1,82 @@
package test.uebung.uebung05.logistics.storage;
import uebung05.logistics.material.Oil;
import uebung05.logistics.storage.IntStorage;
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());
}
}

View File

@@ -0,0 +1,76 @@
package test.uebung.uebung09.collection;
import java.util.Iterator;
import uebung09.collection.Set;
import uebung09.collection.SetFactory;
import java.util.NoSuchElementException;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class SetTest {
static String a = "test";
static String b = "test2";
static String c = "test3";
public static void main(String[] args) {
}
@Test
public void EmptySetTest(){
Set<String> test = SetFactory.create();
Iterator<String> i = test.iterator();
assertFalse(i.hasNext());
assertThrows(NoSuchElementException.class, i::next);
assertFalse(test.contains(a));
assertEquals(0,test.size());
assertTrue(test.isEmpty());
}
@Test
public void SingeltonSetTest(){
Set<String> test = SetFactory.create(a);
Iterator<String> i = test.iterator();
assertTrue(i.hasNext());
assertTrue(a == i.next());
assertFalse(i.hasNext());
assertThrows(NoSuchElementException.class, i::next);
assertTrue(test.contains(a));
assertEquals(1,test.size());
assertFalse(test.isEmpty());
}
@Test
public void BigSetTest() {
Set<String> test = SetFactory.create(a,b,c);
Iterator<String> i = test.iterator();
assertTrue(i.hasNext());
assertTrue(a == i.next());
assertTrue(i.hasNext());
assertTrue(a == i.next());
assertTrue(i.hasNext());
assertTrue(a == i.next());
assertFalse(i.hasNext());
assertThrows(NoSuchElementException.class, i::next);
assertTrue(test.contains(a));
assertEquals(1,test.size());
assertFalse(test.isEmpty());
}
}

View File

@@ -0,0 +1,44 @@
package test.uebung.uebung09.iterator;
import org.junit.Test;
import java.util.Iterator;
import java.util.NoSuchElementException;
import uebung09.iterator.Array2dIterator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public class Array2dIteratorTest {
@Test
public void testArray2dIterator() {
final String[][] array = {{}, {"foo", "bar"}, {"baz"}, {}};
final Iterator<String> it = new Array2dIterator<>(array);
assertTrue(it.hasNext());
assertEquals("foo", it.next());
assertTrue(it.hasNext());
assertEquals("bar", it.next());
assertTrue(it.hasNext());
assertEquals("baz", it.next());
assertFalse(it.hasNext());
assertThrows(NoSuchElementException.class, it::next);
}
@Test
public void testArray2dIteratorOnlyEmpty() {
final String[][] array = {{}, {}, {}};
final Iterator<String> it = new Array2dIterator<>(array);
assertFalse(it.hasNext());
assertThrows(NoSuchElementException.class, it::next);
}
@Test
public void testArray2dIteratorEmpty() {
final String[][] array = {};
final Iterator<String> it = new Array2dIterator<>(array);
assertFalse(it.hasNext());
assertThrows(NoSuchElementException.class, it::next);
}
}

View File

@@ -0,0 +1,124 @@
package test.uebung.uebung09.iterator;
import org.junit.Test;
import java.util.Iterator;
import java.util.NoSuchElementException;
import uebung09.iterator.*;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public class SkipNullIteratorTest {
@Test
public void testEmpty() {
final Iterator<Object> it = new SkipNullIterator<>(emptyList().iterator());
assertFalse(it.hasNext());
assertThrows(NoSuchElementException.class, it::next);
}
@Test
public void testNull() {
final Iterator<Object> it = new SkipNullIterator<>(asList(null, null).iterator());
assertFalse(it.hasNext());
assertThrows(NoSuchElementException.class, it::next);
}
@Test
public void testNonNull() {
final Iterator<String> it = new SkipNullIterator<>(asList("foo").iterator());
assertTrue(it.hasNext());
assertEquals("foo", it.next());
assertFalse(it.hasNext());
assertThrows(NoSuchElementException.class, it::next);
}
@Test
public void testMixed() {
final Iterator<String> it = new SkipNullIterator<>(asList(null, "foo", null).iterator());
assertTrue(it.hasNext());
assertEquals("foo", it.next());
assertFalse(it.hasNext());
assertThrows(NoSuchElementException.class, it::next);
}
@Test
public void testMixed2() {
final Iterator<String> oriIt = asList("a", "b", null, "c").iterator();
Iterator<String> it = new SkipNullIterator<>(oriIt);
assertTrue(it.hasNext());
assertEquals("a", it.next());
assertTrue(it.hasNext());
assertEquals("b", it.next());
assertTrue(it.hasNext());
assertEquals("c", it.next());
assertFalse(it.hasNext());
assertThrows(NoSuchElementException.class, it::next);
}
@Test
public void testDontCallInCtor() {
final Iterator<String> dontCallNext = new Iterator<>() {
@Override
public boolean hasNext() {
throw new RuntimeException();
}
@Override
public String next() {
throw new RuntimeException();
}
};
new SkipNullIterator<>(dontCallNext);
}
@Test
public void testSkipNullIteratorInfinity() {
final Iterator<String> oriIt = new Iterator<>() {
@Override
public boolean hasNext() {
return true;
}
@Override
public String next() {
return "infinity";
}
};
final Iterator<String> it = new SkipNullIterator<>(oriIt);
for (int i = 0; i < 1000; i++) {
assertTrue(it.hasNext());
assertEquals("infinity", it.next());
}
}
@Test
public void testPathological() {
final Iterator<String> oriIt = new Iterator<>() {
private int ctr;
@Override
public boolean hasNext() {
return true;
}
@Override
public String next() {
return ctr++ > 100000 ? "infinity" : null;
}
};
final Iterator<String> it = new SkipNullIterator<>(oriIt);
for (int i = 0; i < 1000; i++) {
assertTrue(it.hasNext());
assertEquals("infinity", it.next());
}
}
}

View File

@@ -1,20 +1,26 @@
package uebung04;
import java.util.ArrayList;
public class ByeGame extends Game{
private String player1;
private String player2;
public ByeGame(String player1, Game player2){
public ByeGame(String player1, String player2){
this.player1 = player1;
this.player2 = player2;
}
public String getPlayer1(){return player1;}
public String getPlayer2(){return player2;}
public ??? getPlayer2(){
return player2.getAllPlayers();
@Override
public ArrayList<String> getAllPlayers() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getAllPlayers'");
}

View File

@@ -7,7 +7,7 @@ public class OrdinaryGame extends Game{
private final int id;
public OrdinaryGame(Game player1, Game player2){
public OrdinaryGame(String player1, String player2){
this.player1 = player1;
this.player2 = player2;
@@ -15,18 +15,16 @@ public class OrdinaryGame extends Game{
counter++;
}
public ArrayList<String> getPlayer1(){
return player1.getAllPlayers();
public String getPlayer1(){
return null;
}
public ArrayList<String> getPlayer2(){
return player2.getAllPlayers();
public String getPlayer2(){
return null;
}
public ArrayList<String> getAllPlayers(){
ArrayList<String> rtn = player1.getAllPlayers();
rtn.addAll(player2.getAllPlayers());
return rtn;
return null;
}
}

View File

@@ -0,0 +1,38 @@
package uebung05.logistics;
import uebung05.logistics.material.BulletBelts;
import uebung05.logistics.material.LiterDiesel;
import uebung05.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());
}
}

View File

@@ -0,0 +1,114 @@
package uebung05.logistics;
import uebung05.logistics.material.BulletBelts;
import uebung05.logistics.material.MetGallonsKerosene;
import uebung05.logistics.material.RocketPods;
import uebung05.logistics.quantities.FloatUnit;
import uebung05.logistics.quantities.IntUnit;
import uebung05.logistics.quantities.NeedCollector;
import uebung05.logistics.storage.FloatStorage;
import uebung05.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();
}
}

View File

@@ -0,0 +1,120 @@
package uebung05.logistics;
import uebung05.logistics.quantities.FloatUnit;
import uebung05.logistics.quantities.IntUnit;
import uebung05.logistics.quantities.NeedCollector;
import uebung05.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<Vehicle> 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
*/
public 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();
}
}

View File

@@ -0,0 +1,38 @@
package uebung05.logistics;
import uebung05.logistics.quantities.FloatUnit;
import uebung05.logistics.quantities.IntUnit;
import java.util.HashMap;
import java.util.Map;
public class NeedCollector {
private Map<IntUnit, Integer> intNeeded;
private Map<FloatUnit, Float> floatNeeded;
public NeedCollector() {
intNeeded = new HashMap<>();
floatNeeded = new HashMap<>();
}
public void add (int amount, IntUnit unit) {
intNeeded.put(unit, amount);
}
public void add (float amount, FloatUnit unit) {
floatNeeded.put(unit, amount);
}
public int getNeed (IntUnit unit) {
return intNeeded.get(unit);
}
public float getNeed (FloatUnit unit) {
return floatNeeded.get(unit);
}
public void show () {
}
}

112
src/uebung05/logistics/Tank.java Executable file
View File

@@ -0,0 +1,112 @@
package uebung05.logistics;
import uebung05.logistics.material.BulletBelts;
import uebung05.logistics.material.LiterDiesel;
import uebung05.logistics.material.ShellBatches;
import uebung05.logistics.quantities.FloatUnit;
import uebung05.logistics.quantities.IntUnit;
import uebung05.logistics.quantities.NeedCollector;
import uebung05.logistics.storage.FloatStorage;
import uebung05.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();
}
}

104
src/uebung05/logistics/Truck.java Executable file
View File

@@ -0,0 +1,104 @@
package uebung05.logistics;
import uebung05.logistics.material.BulletBelts;
import uebung05.logistics.material.LiterDiesel;
import uebung05.logistics.quantities.FloatUnit;
import uebung05.logistics.quantities.IntUnit;
import uebung05.logistics.quantities.NeedCollector;
import uebung05.logistics.storage.FloatStorage;
import uebung05.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 {
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();
}
}

View File

@@ -0,0 +1,105 @@
package uebung05.logistics;
import uebung05.logistics.material.Grease;
import uebung05.logistics.material.Oil;
import uebung05.logistics.quantities.FloatUnit;
import uebung05.logistics.quantities.IntUnit;
import uebung05.logistics.quantities.NeedCollector;
import uebung05.logistics.storage.IntStorage;
/**
* 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 {
String name;
IntStorage oil;
IntStorage grease;
private final static int maxOil = 3;
private final static int maxGrease = 3;
/**
* 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);
}
/**
* 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;
}
}

View File

@@ -0,0 +1,39 @@
package uebung05.logistics.material;
import uebung05.logistics.quantities.IntUnit;
/**
* 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 {
public 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 "belts of 7.62 bullets";
}
}

View File

@@ -0,0 +1,39 @@
package uebung05.logistics.material;
import uebung05.logistics.quantities.IntUnit;
/**
* 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 {
public 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 "units of grease";
}
}

View File

@@ -0,0 +1,39 @@
package uebung05.logistics.material;
import uebung05.logistics.quantities.FloatUnit;
/**
* 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 {
public 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 "liters of diesel";
}
}

View File

@@ -0,0 +1,39 @@
package uebung05.logistics.material;
import uebung05.logistics.quantities.FloatUnit;
/**
* 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 {
public 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 "met gallons of kerosene";
}
}

View File

@@ -0,0 +1,39 @@
package uebung05.logistics.material;
import uebung05.logistics.quantities.IntUnit;
/**
* 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 {
public 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 "units of oil";
}
}

View File

@@ -0,0 +1,58 @@
package uebung05.logistics.material;
import uebung05.logistics.quantities.IntUnit;
/**
* 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 {
public 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 "pods of 70mm rockets";
}
/**
* 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;
}
}

Some files were not shown because too many files have changed in this diff Show More