This commit is contained in:
2024-05-16 18:07:20 +02:00
parent b24f7c05c0
commit 65da2599bd
36 changed files with 559 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
package uebung05.logistics;
public class Demo {
public static void main(String[] args) {
}
}

View File

@@ -0,0 +1,5 @@
package uebung05.logistics;
public class Helicopter extends Vehicle{
}

View File

@@ -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<IntUnit, Integer> intNeeded;
private Map<FloatUnit, Float> 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(){
}
}

View File

@@ -0,0 +1,5 @@
package uebung05.logistics;
public class Tank extends Vehicle{
}

View File

@@ -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);
}
}

View File

@@ -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<IntUnit, Integer> materials;
protected abstract void reportNeeds(NeedCollector collector);
protected abstract void fillUpAll();
protected abstract void consumeAll(int intensityRate);
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,5 @@
package uebung05.logistics.quantities;
public interface FloatUnit {
}

View File

@@ -0,0 +1,5 @@
package uebung05.logistics.quantities;
public interface IntUnit {
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}