Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PourMove implements Move {
- //PROPERTIES
- int idBottleGifter;
- //The reference of the bottle we want to pick water from.
- int idBottleReceiver;
- //The reference of the bottle we want to transfer water to.
- private int quantity;
- //The quantity of water filled/emptied in the bottle
- private int TRANSFERRED_QUANTITY;
- //The tranferred quantity from one bottle to another
- private String GIFTER_BOTTLE_NAME;
- private String RECEIVER_BOTTLE_NAME;
- //The names of the bottles for better identification
- private int selector;
- // The selector value is here to select if we 1 : fill the bottle or 2 : empty the bottle; 0 is the initial unused value
- //CONSTRUCTOR
- public PourMove(int idBottleGifter, int idBottleReceiver){
- this.idBottleGifter = idBottleGifter;
- this.idBottleReceiver = idBottleReceiver;
- this.selector = 0;
- }
- //GETTERS SETTERS
- //METHODS
- public void apply(Configuration configuration){
- this.selector = 1;
- GIFTER_BOTTLE_NAME = configuration.getListBottle().get(idBottleGifter).getBOTTLE_NAME();
- RECEIVER_BOTTLE_NAME = configuration.getListBottle().get(idBottleReceiver).getBOTTLE_NAME();
- configuration.getListBottle().get(idBottleGifter).transfer(configuration.getListBottle().get(idBottleReceiver));
- TRANSFERRED_QUANTITY = configuration.getListBottle().get(idBottleGifter).getTransferredQuantity();
- }
- public void reverse(Configuration configuration){
- configuration.getListBottle().get(idBottleGifter).addWater(TRANSFERRED_QUANTITY);
- configuration.getListBottle().get(idBottleReceiver).removeWater(TRANSFERRED_QUANTITY);
- }
- public void display(){
- System.out.println("Pour " + TRANSFERRED_QUANTITY + "L from " + GIFTER_BOTTLE_NAME + " to " + RECEIVER_BOTTLE_NAME );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement