oop/src/uebung05/logistics/Helicopter.java
2024-05-21 14:18:10 +00:00

114 lines
3.7 KiB
Java
Executable File

package logistics;
import logistics.material.BulletBelts;
import logistics.material.MetGallonsKerosene;
import logistics.material.RocketPods;
import logistics.quantities.FloatUnit;
import logistics.quantities.IntUnit;
import logistics.quantities.NeedCollector;
import logistics.storage.FloatStorage;
import logistics.storage.IntStorage;
/**
* The Helicopter class represents a helicopter in the logistics system.
* It extends the Vehicle abstract class and includes a tank for kerosene,
* a storage for bullet belts, and a storage for rocket pods, and the necessary methods
* for reporting needs, filling up, and consuming supplies.
*
* @author Nikolaus Köberlein
* @version 1.0
*/
public class Helicopter extends Vehicle {
FloatStorage tank;
IntStorage bullets;
IntStorage rockets;
private final static int maxAmmunition = 2;
private final static int maxFuel = 500;
/**
* Construct a Helicopter object with a name, kerosene amount, bullet belts amount, and rocket pods amount
*
* @param name The name of the helicopter
* @param kerosine The initial amount of kerosene for the helicopter
* @param bulletsBelts The initial amount of bullet belts for the helicopter
* @param rocketPods The initial amount of rocket pods for the helicopter
*/
public Helicopter(String name, float kerosine, int bulletsBelts, int rocketPods) {
super(name, 3, 3);
this.bullets = new IntStorage(bulletsBelts, BulletBelts.getINSTANCE(), maxAmmunition);
this.rockets = new IntStorage(rocketPods, RocketPods.getINSTANCE(), maxAmmunition);
this.tank = new FloatStorage(kerosine, MetGallonsKerosene.getINSTANCE(), maxFuel);
}
/**
* Construct a Helicopter object with a name, kerosene amount, bullet belts amount, and rocket pods amount
*
* @param name The name of the helicopter
*/
public Helicopter(String name) {
this(name, 0, 0, 0);
}
/**
* Report the needs of the helicopter to a NeedCollector object
*
* @param collector The NeedCollector object to which to report the needs
*/
@Override
public void reportNeeds(NeedCollector collector) {
tank.reportNeed(collector);
bullets.reportNeed(collector);
rockets.reportNeed(collector);
super.reportBasicNeeds(collector);
}
/**
* Fill up all the supplies for the helicopter
*/
@Override
public void fillUpAll() {
tank.fillUp();
bullets.fillUp();
rockets.fillUp();
super.fillUpBasic();
}
/**
* Consume the helicopter's supplies based on the intensity rate
*
* @param intensityRate The intensity rate for the consumption
*/
@Override
public void consumeAll(int intensityRate) {
tank.consume(intensityRate*200);
bullets.consume(intensityRate);
rockets.consume(intensityRate);
super.consumeBasic();
}
/**
* Check if the helicopter needs a specific IntUnit object
*
* @param unit The IntUnit object for which to check the need
* @return True if the helicopter needs the IntUnit object, false otherwise
*/
@Override
public Boolean need(IntUnit unit) {
return unit == bullets.getUnit() || unit == rockets.getUnit() || unit == oil.getUnit() || unit == grease.getUnit();
}
/**
* Check if the helicopter needs a specific FloatUnit object
*
* @param unit The FloatUnit object for which to check the need
* @return True if the helicopter needs the FloatUnit object, false otherwise
*/
@Override
public Boolean need(FloatUnit unit) {
return unit == tank.getUnit();
}
}