Files
oop/src/uebung05/logistics/Tank.java
2024-06-14 01:03:45 +02:00

112 lines
3.6 KiB
Java
Executable File

package uebung05.logistics;
import uebung05.logistics.material.BulletBelts;
import uebung05.logistics.material.LiterDiesel;
import uebung05.logistics.material.ShellBatches;
import uebung05.logistics.quantities.FloatUnit;
import uebung05.logistics.quantities.IntUnit;
import uebung05.logistics.quantities.NeedCollector;
import uebung05.logistics.storage.FloatStorage;
import uebung05.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();
}
}