Compare commits
	
		
			2 Commits
		
	
	
		
			2a8bb9262f
			...
			a021a64624
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a021a64624 | |||
| 65da2599bd | 
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/Demo.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/Demo.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/Helicopter.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/Helicopter.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/NeedCollector.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/NeedCollector.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/Tank.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/Tank.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/Truck.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/Truck.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/Vehicle.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/Vehicle.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/BulletBelts.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/BulletBelts.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/Grease.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/Grease.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/LiterDiesel.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/LiterDiesel.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/MetGallonsKerosene.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/MetGallonsKerosene.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/Oil.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/Oil.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/RocketPods.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/RocketPods.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/ShellBatches.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/material/ShellBatches.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/quantities/FloatUnit.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/quantities/FloatUnit.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/quantities/IntUnit.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/quantities/IntUnit.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/storage/FloatStorage.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/storage/FloatStorage.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/uebung05/logistics/storage/IntStorage.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/uebung05/logistics/storage/IntStorage.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										67
									
								
								test/uebung/uebung05/logistics/ManagerTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								test/uebung/uebung05/logistics/ManagerTest.java
									
									
									
									
									
										Normal file
									
								
							@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										80
									
								
								test/uebung/uebung05/logistics/storage/IntStorageTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								test/uebung/uebung05/logistics/storage/IntStorageTest.java
									
									
									
									
									
										Normal file
									
								
							@@ -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());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user