meh
This commit is contained in:
9
src/uebung05/logistics/Demo.java
Normal file
9
src/uebung05/logistics/Demo.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package uebung05.logistics;
|
||||
|
||||
public class Demo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
5
src/uebung05/logistics/Helicopter.java
Normal file
5
src/uebung05/logistics/Helicopter.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package uebung05.logistics;
|
||||
|
||||
public class Helicopter extends Vehicle{
|
||||
|
||||
}
|
||||
60
src/uebung05/logistics/NeedCollector.java
Normal file
60
src/uebung05/logistics/NeedCollector.java
Normal 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(){
|
||||
|
||||
}
|
||||
}
|
||||
5
src/uebung05/logistics/Tank.java
Normal file
5
src/uebung05/logistics/Tank.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package uebung05.logistics;
|
||||
|
||||
public class Tank extends Vehicle{
|
||||
|
||||
}
|
||||
17
src/uebung05/logistics/Truck.java
Normal file
17
src/uebung05/logistics/Truck.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
16
src/uebung05/logistics/Vehicle.java
Normal file
16
src/uebung05/logistics/Vehicle.java
Normal 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);
|
||||
}
|
||||
24
src/uebung05/logistics/material/BulletBelts.java
Normal file
24
src/uebung05/logistics/material/BulletBelts.java
Normal 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;
|
||||
}
|
||||
}
|
||||
25
src/uebung05/logistics/material/Grease.java
Normal file
25
src/uebung05/logistics/material/Grease.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
25
src/uebung05/logistics/material/LiterDiesel.java
Normal file
25
src/uebung05/logistics/material/LiterDiesel.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
25
src/uebung05/logistics/material/MetGallonsKerosene.java
Normal file
25
src/uebung05/logistics/material/MetGallonsKerosene.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
24
src/uebung05/logistics/material/Oil.java
Normal file
24
src/uebung05/logistics/material/Oil.java
Normal 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;
|
||||
}
|
||||
}
|
||||
24
src/uebung05/logistics/material/RocketPods.java
Normal file
24
src/uebung05/logistics/material/RocketPods.java
Normal 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;
|
||||
}
|
||||
}
|
||||
25
src/uebung05/logistics/material/ShellBatches.java
Normal file
25
src/uebung05/logistics/material/ShellBatches.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
5
src/uebung05/logistics/quantities/FloatUnit.java
Normal file
5
src/uebung05/logistics/quantities/FloatUnit.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package uebung05.logistics.quantities;
|
||||
|
||||
public interface FloatUnit {
|
||||
|
||||
}
|
||||
5
src/uebung05/logistics/quantities/IntUnit.java
Normal file
5
src/uebung05/logistics/quantities/IntUnit.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package uebung05.logistics.quantities;
|
||||
|
||||
public interface IntUnit {
|
||||
|
||||
}
|
||||
60
src/uebung05/logistics/storage/FloatStorage.java
Normal file
60
src/uebung05/logistics/storage/FloatStorage.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
58
src/uebung05/logistics/storage/IntStorage.java
Normal file
58
src/uebung05/logistics/storage/IntStorage.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user