Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class MixingMilk {
  5.  
  6. public static void main(String[] args) throws IOException {
  7. // TODO Auto-generated method stub
  8. Scanner input = new Scanner(new File("mixmilk.out"));
  9. PrintWriter pw = new PrintWriter(new File("mixmilk.out"));
  10. Bucket one = new Bucket(input.nextInt(), input.nextInt());
  11. Bucket two = new Bucket(input.nextInt(), input.nextInt());
  12. Bucket three = new Bucket(input.nextInt(), input.nextInt());
  13. int temp;
  14. for (int i = 0; i < 33; i++)
  15. {
  16. temp = two.add(one.getCurrent());
  17.  
  18. one.setCurrent(temp);
  19. System.out.println("One = " + one.getCurrent() + "Two = " + two.getCurrent() + "Three = " + three.getCurrent());
  20.  
  21. temp = three.add(two.getCurrent());
  22. two.setCurrent(temp);
  23. System.out.println("One = " + one.getCurrent() + "Two = " + two.getCurrent() + "Three = " + three.getCurrent());
  24.  
  25. temp = one.add(three.getCurrent());
  26. three.setCurrent(temp);
  27. System.out.println("ASSFSDOne = " + one.getCurrent() + "Two = " + two.getCurrent() + "Three = " + three.getCurrent());
  28. }
  29. temp = two.add(one.getCurrent());
  30. one.setCurrent(temp);
  31. System.out.println("One = " + one.getCurrent() + "Two = " + two.getCurrent() + "Three = " + three.getCurrent());
  32. pw.println(one.getCurrent());
  33. pw.println(two.getCurrent());
  34. pw.println(three.getCurrent());
  35. pw.close();
  36. }
  37. static class Bucket
  38. {
  39. private int capacity;
  40. private int current;
  41. Bucket(int capacity, int current)
  42. {
  43. this.capacity = capacity;
  44. this.current = current;
  45. }
  46. int getCapacity()
  47. {
  48. return capacity;
  49. }
  50. int getCurrent()
  51. {
  52. return current;
  53. }
  54. int add(int n)
  55. {
  56. int space = capacity - current;
  57. if (current+n <= capacity)
  58. {
  59. current += n;
  60. return 0;
  61. }
  62. else
  63. {
  64. int temp = n - space;
  65. System.out.println(temp);
  66. current = capacity;
  67. return temp;
  68. }
  69. }
  70. void setCurrent(int n)
  71. {
  72. current = n;
  73. }
  74. void remove(int n)
  75. {
  76. current -= n;
  77. }
  78. void print()
  79. {
  80. System.out.println("Current = " + current);
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement