Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class MixingMilk {
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- Scanner input = new Scanner(new File("mixmilk.out"));
- PrintWriter pw = new PrintWriter(new File("mixmilk.out"));
- Bucket one = new Bucket(input.nextInt(), input.nextInt());
- Bucket two = new Bucket(input.nextInt(), input.nextInt());
- Bucket three = new Bucket(input.nextInt(), input.nextInt());
- int temp;
- for (int i = 0; i < 33; i++)
- {
- temp = two.add(one.getCurrent());
- one.setCurrent(temp);
- System.out.println("One = " + one.getCurrent() + "Two = " + two.getCurrent() + "Three = " + three.getCurrent());
- temp = three.add(two.getCurrent());
- two.setCurrent(temp);
- System.out.println("One = " + one.getCurrent() + "Two = " + two.getCurrent() + "Three = " + three.getCurrent());
- temp = one.add(three.getCurrent());
- three.setCurrent(temp);
- System.out.println("ASSFSDOne = " + one.getCurrent() + "Two = " + two.getCurrent() + "Three = " + three.getCurrent());
- }
- temp = two.add(one.getCurrent());
- one.setCurrent(temp);
- System.out.println("One = " + one.getCurrent() + "Two = " + two.getCurrent() + "Three = " + three.getCurrent());
- pw.println(one.getCurrent());
- pw.println(two.getCurrent());
- pw.println(three.getCurrent());
- pw.close();
- }
- static class Bucket
- {
- private int capacity;
- private int current;
- Bucket(int capacity, int current)
- {
- this.capacity = capacity;
- this.current = current;
- }
- int getCapacity()
- {
- return capacity;
- }
- int getCurrent()
- {
- return current;
- }
- int add(int n)
- {
- int space = capacity - current;
- if (current+n <= capacity)
- {
- current += n;
- return 0;
- }
- else
- {
- int temp = n - space;
- System.out.println(temp);
- current = capacity;
- return temp;
- }
- }
- void setCurrent(int n)
- {
- current = n;
- }
- void remove(int n)
- {
- current -= n;
- }
- void print()
- {
- System.out.println("Current = " + current);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement