aboutsummaryrefslogtreecommitdiff
path: root/Practical2/src/nl/camilstaps/cs/CheckoutHelper.java
blob: 5ad7d2dac39c27f4fbb5cd01eb7d2ece2b795876 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package nl.camilstaps.cs;

import java.util.ArrayList;

/**
 * Created by camil on 11/28/15.
 */
class CheckoutHelper {
    private final ArrayList<Integer> products = new ArrayList<>();
    private int minimal_price;

    public CheckoutHelper() {
    }

    public int minimumPayment(int dividers) {
        int sum = minimal_price;
        for (int n : products)
            sum += n;
        return sum;
    }

    public void addProduct(int price) {
        int has_to_pay = price / 5;
        int rest = price % 5;

        minimal_price += has_to_pay;
        if (rest != 0) {
            products.add(rest);
        }
    }

}