// @topic T11719 MVC Demo - Account Balance
// @brief Business Object

package banking;

public class Account {
    // data attributes
    double balance;
    ControllerTransaction controller = null;
    
    // constructors
    public Account(double balance) {
        this.balance = balance;
    }
    
    // operations

    public ControllerTransaction getController() {
        return controller;
    }

    public void setController(ControllerTransaction controller) {
        this.controller = controller;
    }
    
    
    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }
    
    public void withdraw( double amount )
    {
        if ( balance >= amount ) {
            // sufficient funds -- ok to proceed
            balance -= amount;
            if ( controller != null ) {
                controller.balanceChanged( balance );
            }
        } else {
            // overdraft attempt
            throw new RuntimeException("overdraft");
        }
    }
    
    public void deposit( double amount )
    {
        balance += amount;
    }
    
}//class Account