Skip to the content.
package com.bookshop.dry;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * The single source of one piece of business knowledge: how VAT is applied.
 * When the rate or rounding rule changes, this is the only file that changes.
 */
public final class Vat {

    public static final BigDecimal STANDARD_RATE = new BigDecimal("0.20");

    private Vat() {
    }

    public static BigDecimal withVat(BigDecimal netAmount) {
        return netAmount.add(vatOn(netAmount));
    }

    public static BigDecimal vatOn(BigDecimal netAmount) {
        return netAmount.multiply(STANDARD_RATE).setScale(2, RoundingMode.HALF_UP);
    }
}

Raw file