/* * @author KR * Account.java * Project Assignment */ public class Account { //Define account balance variable. We could include other information such //as account owner's name, but we are going to keep the constructor very //simple, and include only one accessor method to return balance(see below). private double balance; /****************** Constructor Methods *********************/ //Construct an account with a provided initial balance. public Account( double inputBalance ) { //Initialize balance with value provided balance = inputBalance; } /******************* Accessor ("Get") Methods ********************/ //Accessor method to retrieve balance of account public double getBalance() { return balance; } /******************* Mutator ("Set") Methods *********************/ //Mutator method to decrease account balance, simulating a cash withdrawal //or a check deducted. Before deducting amount, check if sufficient funds. public void withdraw ( double someAmount ) { if ( enoughFunds(someAmount) ) { // there is enough money to deduct the check amount balance = balance - someAmount; } // else not enough money; do not withdraw amount } //Mutator method to increase account balance, simulating a cash deposit public void deposit ( double anotherAmount ) { balance = balance + anotherAmount; } /***************** Facilitator ("Helper") Methods *****************/ //Faciliator method to check if sufficient funds for withdrawal. Account must //have a minimum of $100.00 balance. public boolean enoughFunds ( double anAmount ) { //If balance is large enough to subtract amount of check and still have //$100 left, then return true. Otherwise, return false. return ( (balance - anAmount) >= 100.0 ); } /******************* toString Methods *********************/ //Returns a useful String representation of the account object public String toString() { return "balance is now $" + balance; } }