import java.math.BigDecimal;
import java.math.MathContext;

/**
 * Created by K_A_Volchica on 19.03.2015.
 */
public class Quantity {
    private BigDecimal amount;
    private Kind kind;

    public Quantity(BigDecimal amount, Kind kind) {
        this.amount = amount;
        this.kind = kind;
    }

    public Quantity(String amount, Kind kind) {
        this(new BigDecimal(amount), kind);
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public Kind getKind() {
        return kind;
    }

    public void setKind(Kind kind) {
        this.kind = kind;
    }

    @Override
    public String toString() {
        return amount + " " + kind;
    }

    public Quantity add(Quantity s2) {
        BigDecimal s2amount = s2.amount;
        if (this.kind != s2.kind) {
            throw new IllegalArgumentException("Cannot convert kind");
        }
        BigDecimal sum = this.amount.add(s2amount);
        return new Quantity(sum, this.kind);
    }

    public Quantity subtract(Quantity s2) {
        BigDecimal s2amount = s2.amount;
        if (this.kind != s2.kind) {
            throw new IllegalArgumentException("Cannot convert kind");
        }
        BigDecimal sub = this.amount.subtract(s2amount);
        return new Quantity(sub, this.kind);
    }

    public Quantity multiply (BigDecimal s) {
        BigDecimal sub = this.amount.multiply(s);
        return new Quantity(sub, this.kind);
    }
    public Quantity divide (BigDecimal s) {
        BigDecimal sub = this.amount.divide(s);
        return new Quantity(sub, this.kind);
    }
}
