updated uebung05 from lsg
This commit is contained in:
113
src/uebung05/logistics/Tank.java
Normal file → Executable file
113
src/uebung05/logistics/Tank.java
Normal file → Executable file
@@ -1,5 +1,112 @@
|
||||
package uebung05.logistics;
|
||||
package logistics;
|
||||
|
||||
public class Tank extends Vehicle{
|
||||
import logistics.material.BulletBelts;
|
||||
import logistics.material.LiterDiesel;
|
||||
import logistics.material.ShellBatches;
|
||||
import logistics.quantities.FloatUnit;
|
||||
import logistics.quantities.IntUnit;
|
||||
import logistics.quantities.NeedCollector;
|
||||
import logistics.storage.FloatStorage;
|
||||
import logistics.storage.IntStorage;
|
||||
|
||||
}
|
||||
/**
|
||||
* The Tank class represents a tank in the logistics system.
|
||||
* It extends the Vehicle abstract class and includes a tank for diesel, a storage for bullet belts,
|
||||
* and a storage for shell batches, and the necessary methods for reporting needs, filling up, and consuming supplies.
|
||||
*
|
||||
* @author Nikolaus Köberlein
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Tank extends Vehicle {
|
||||
|
||||
FloatStorage tank;
|
||||
IntStorage shell;
|
||||
IntStorage bullets;
|
||||
|
||||
private final static int maxAmmunition = 10;
|
||||
private final static int maxFuel = 1200;
|
||||
|
||||
/**
|
||||
* Construct a Tank object with a name, diesel amount, bullet belts amount, and shell batches amount
|
||||
*
|
||||
* @param name The name of the tank
|
||||
* @param diesel The initial amount of diesel for the tank
|
||||
* @param bulletBelts The initial amount of bullet belts for the tank
|
||||
* @param shellBatches The initial amount of shell batches for the tank
|
||||
*/
|
||||
public Tank(String name, float diesel, int bulletBelts, int shellBatches) {
|
||||
super(name, 3, 3);
|
||||
|
||||
this.shell = new IntStorage(shellBatches, ShellBatches.getINSTANCE(), maxAmmunition);
|
||||
this.bullets = new IntStorage(bulletBelts, BulletBelts.getINSTANCE(), maxAmmunition);
|
||||
this.tank = new FloatStorage(diesel, LiterDiesel.getINSTANCE(), maxFuel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Tank object with a name
|
||||
*
|
||||
* @param name The name of the tank
|
||||
*/
|
||||
public Tank(String name) {
|
||||
this(name, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Report the needs of the tank to a NeedCollector object
|
||||
*
|
||||
* @param collector The NeedCollector object to which to report the needs
|
||||
*/
|
||||
@Override
|
||||
public void reportNeeds(NeedCollector collector) {
|
||||
tank.reportNeed(collector);
|
||||
shell.reportNeed(collector);
|
||||
bullets.reportNeed(collector);
|
||||
super.reportBasicNeeds(collector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill up all the supplies for the tank
|
||||
*/
|
||||
@Override
|
||||
public void fillUpAll() {
|
||||
tank.fillUp();
|
||||
shell.fillUp();
|
||||
bullets.fillUp();
|
||||
super.fillUpBasic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume the tank's supplies based on the intensity rate
|
||||
*
|
||||
* @param intensityRate The intensity rate for the consumption
|
||||
*/
|
||||
@Override
|
||||
public void consumeAll(int intensityRate) {
|
||||
tank.consume(intensityRate*180);
|
||||
bullets.consume(intensityRate*2);
|
||||
shell.consume(intensityRate*2);
|
||||
super.consumeBasic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the tank needs a specific IntUnit object
|
||||
*
|
||||
* @param unit The IntUnit object for which to check the need
|
||||
* @return True if the tank needs the IntUnit object, false otherwise
|
||||
*/
|
||||
@Override
|
||||
public Boolean need(IntUnit unit) {
|
||||
return unit == shell.getUnit() || unit == bullets.getUnit() || unit == oil.getUnit() || unit == grease.getUnit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the tank needs a specific FloatUnit object
|
||||
*
|
||||
* @param unit The FloatUnit object for which to check the need
|
||||
* @return True if the tank needs the FloatUnit object, false otherwise
|
||||
*/
|
||||
@Override
|
||||
public Boolean need(FloatUnit unit) {
|
||||
return unit == tank.getUnit();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user