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