001    package topdown.service;
002    
003    /**
004     * This class represents a bank account.
005     */
006    public class Account {
007    
008        /** The account owner's name. */
009        private String m_accountName;
010    
011        /** The account balance. */
012        private float m_accountBalance;
013    
014        /** The account ID. */
015        private String m_accountID;
016    
017        /**
018         * Creates a bank account.
019         * @param name  The name of the account owner.
020         * @param balance   The beginning balance of the account.
021         * @throws  AccountException    if there are not sufficient funds (>0) for the initial balance.
022         */
023        public Account(String name, float balance) throws AccountException {
024            if(balance <= 0f){
025                AccountException ae =new AccountException("Insufficient funds for new account.  You must start an account with more than $0");
026               throw ae;
027            }
028            m_accountBalance = balance;
029            m_accountName = name;
030            try{
031                m_accountID = java.net.InetAddress.getLocalHost().getHostAddress();
032                m_accountID += "_" + name;
033            }
034            catch(Exception ex){
035                m_accountID = "test_" + name;
036                ex.printStackTrace();
037            }
038        }
039    
040        /**
041         * Returns the account owner's name.
042         * @return  the owner's name.
043         */
044        public String getAccountName() {
045            return m_accountName;
046        }
047    
048        /**
049         * Sets the account owner's name.
050         * @param accountName   the name of the account owner.
051         */
052        public void setAccountName(String accountName) {
053            m_accountName = accountName;
054        }
055    
056        /**
057         * Returns the account ID.
058         * @return  the account ID.
059         */
060        public String getAccountID() {
061            return m_accountID;
062        }
063    
064        /**
065         * Sets the account ID.
066         * @param accountID the account ID.
067         */
068        public void setAccountID(String accountID) {
069            m_accountID = accountID;
070        }
071    
072        /**
073         * Returns the current balance of the account.
074         * @return  the account balance.
075         */
076        public float getBalance(){
077            return m_accountBalance;
078        }
079    
080        /**
081         * Deposits funds into the account and updates the balance.
082         * @param funds the amount of funds to deposit.
083         */
084        public void deposit(float funds){
085            m_accountBalance += funds;
086        }
087    
088        /**
089         * Withdraws funds from the account and updates the balance accordingly.
090         * @param funds the amount of money to withdraw.
091         * @throws AccountException if the amount exceeds the maximum allowed withdrawl ($2000.00).
092         */
093        public void withdraw(float funds) throws AccountException {
094            if (funds >= 2000.00f) {
095                AccountException ae = new AccountException("Exceeded maximum withdrawal of $2000.00");
096                throw ae;
097            }
098            m_accountBalance -= funds;
099        }
100    
101    }