meh
This commit is contained in:
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