Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. public class PourMove implements Move {
  2.  
  3. //PROPERTIES
  4.  
  5. int idBottleGifter;
  6. //The reference of the bottle we want to pick water from.
  7. int idBottleReceiver;
  8. //The reference of the bottle we want to transfer water to.
  9. private int quantity;
  10. //The quantity of water filled/emptied in the bottle
  11. private int TRANSFERRED_QUANTITY;
  12. //The tranferred quantity from one bottle to another
  13. private String GIFTER_BOTTLE_NAME;
  14. private String RECEIVER_BOTTLE_NAME;
  15. //The names of the bottles for better identification
  16. private int selector;
  17. // The selector value is here to select if we 1 : fill the bottle or 2 : empty the bottle; 0 is the initial unused value
  18.  
  19.  
  20. //CONSTRUCTOR
  21.  
  22. public PourMove(int idBottleGifter, int idBottleReceiver){
  23. this.idBottleGifter = idBottleGifter;
  24. this.idBottleReceiver = idBottleReceiver;
  25. this.selector = 0;
  26. }
  27.  
  28. //GETTERS SETTERS
  29.  
  30. //METHODS
  31.  
  32. public void apply(Configuration configuration){
  33. this.selector = 1;
  34. GIFTER_BOTTLE_NAME = configuration.getListBottle().get(idBottleGifter).getBOTTLE_NAME();
  35. RECEIVER_BOTTLE_NAME = configuration.getListBottle().get(idBottleReceiver).getBOTTLE_NAME();
  36. configuration.getListBottle().get(idBottleGifter).transfer(configuration.getListBottle().get(idBottleReceiver));
  37. TRANSFERRED_QUANTITY = configuration.getListBottle().get(idBottleGifter).getTransferredQuantity();
  38. }
  39.  
  40. public void reverse(Configuration configuration){
  41. configuration.getListBottle().get(idBottleGifter).addWater(TRANSFERRED_QUANTITY);
  42. configuration.getListBottle().get(idBottleReceiver).removeWater(TRANSFERRED_QUANTITY);
  43. }
  44.  
  45. public void display(){
  46. System.out.println("Pour " + TRANSFERRED_QUANTITY + "L from " + GIFTER_BOTTLE_NAME + " to " + RECEIVER_BOTTLE_NAME );
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement