package com.javaconcurrencyinpractice.avoidinglivenesshazards.transfermoney;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by joseph.wang on 2017/4/10.
 */
public class Account {
    private DollarAmount balance = new DollarAmount(0);
    private final int acctNo;
    private static final AtomicInteger sequence = new AtomicInteger();

    public Account() {
        acctNo = sequence.incrementAndGet();
    }

    void debit(DollarAmount d) {
        balance = balance.subtract(d);
    }

    void credit(DollarAmount d) {
        balance = balance.add(d);
    }

    DollarAmount getBalance() {
        return balance;
    }

    int getAcctNo() {
        return acctNo;
    }
}
