package by.vorokhobko.question;

import java.util.ArrayList;

/**
 * ATM.
 *
 * Class ATM class for get change 002, lesson test.
 * @author Evgeny Vorokhobko (vorokhobko2011@yandex.ru).
 * @since 15.11.2017.
 * @version 1.
 */
public class ATM {
    /**
     * The class field.
     */
    private static final int CENT_1  = 1;
    /**
     * The class field.
     */
    private static final int CENT_2  = 2;
    /**
     * The class field.
     */
    private static final int CENT_5  = 5;
    /**
     * The class field.
     */
    private static final int CENT_10  = 10;
    /**
     * The class field.
     */
    private ArrayList<Integer> change = new ArrayList<>();
    /**
     * The method get users changes.
     * @param value - value.
     * @param price - price.
     * @return tag.
     * @throws NullException tag.
     */
    public ArrayList<Integer> changes(int value, int price) throws NullException {
        int result = value - price;
        if (result < 0) {
            throw new NullException("Could you put much money, please?");
        }
        if (result / CENT_10 > 0) {
            int last = lastNumber(result, CENT_10);
            if (CENT_5 > last) {
                int set = lastNumber(last, CENT_2);
                if (CENT_2 > set) {
                    if (CENT_1 == set) {
                        change.add(CENT_1);
                    }
                } else {
                    int stop = lastNumber(set, CENT_2);
                    if (CENT_1 == stop) {
                        change.add(CENT_1);
                    }
                }
            } else {
                int cost = lastNumber(last, CENT_5);
                if (CENT_2 < cost) {
                    int lastIndex = lastNumber(cost, CENT_2);
                    if (CENT_1 == lastIndex) {
                        change.add(CENT_1);
                    }
                } else {
                    if (CENT_1 == cost) {
                        change.add(CENT_1);
                    }
                }
            }
        }
        return this.change;
    }
    /**
     * The method helps the method change.
     * @param result - result.
     * @param element - element.
     * @return tag.
     */
    private int lastNumber(int result, int element) {
        int count = result / element;
        int start = element * count;
        result -= start;
        while (start != 0) {
            start -= element;
            change.add(element);
        }
        return result;
    }
}
@@ -311,268 +311,31 @@
  int
- CENT_1  = 1;%0A    /**%0A     * The class field.%0A     */%0A    private static final int CENT_2  = 2;%0A    /**%0A     * The class field.%0A     */%0A    private static final int CENT_5  = 5;%0A    /**%0A     * The class field.%0A     */%0A    private static final int CENT_10  = 10
+%5B%5D DATA = %7B10, 5, 2, 1%7D
 ;%0A  
@@ -825,34 +825,37 @@
       %7D%0A        
-if
+while
  (result / CENT_
@@ -851,18 +851,8 @@
 ult 
-/ CENT_10 
 %3E 0)
@@ -870,1398 +870,248 @@
     
-int last = lastNumber(result, CENT_10);%0A            if (CENT_5 %3E last) %7B%0A                int set = lastNumber(last, CENT_2);%0A                if (CENT_2 %3E set) %7B%0A                    if (CENT_1 == set) %7B%0A                        change.add(CENT_1);%0A                    %7D%0A                %7D else %7B%0A                    int stop = lastNumber(set, CENT_2);%0A                    if (CENT_1 == stop) %7B%0A                        change.add(CENT_1);%0A                    %7D%0A                %7D%0A            %7D else %7B%0A                int cost = lastNumber(last, CENT_5);%0A                if (CENT_2 %3C cost) %7B%0A                    int lastIndex = lastNumber(cost, CENT_2);%0A                    if (CENT_1 == lastIndex) %7B%0A                        change.add(CENT_1);%0A                    %7D%0A                %7D else %7B%0A                    if (CENT_1 == cost) %7B%0A                        change.add(CENT_1);%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return this.change;%0A    %7D%0A    /**%0A     * The method helps the method change.%0A     * @param result - result.%0A     * @param element - element.%0A     * @return tag.%0A     */%0A    private int lastNumber(int result, int element) %7B%0A        int count = result / element;%0A        int start = element * count;%0A        result -= start;%0A        while (start != 0) %7B%0A            start -= element;%0A            change.add(element);%0A        %7D%0A        return result
+for (int coin : DATA) %7B%0A                if (result - coin %3E= 0) %7B%0A                    this.change.add(coin);%0A                    result -= coin;%0A                    break;%0A                %7D%0A            %7D%0A        %7D%0A        return this.change
 ;%0A  

update Банкомат с мелочью