Write a SavingsAccount class to store the following information related to a bank account:
Account number, Password, Branch name, Surnames, First names, Balance
The account balance should be able to reflect cents as well as rands. Assume the balance for a new account is at first 0.
No instance variable should be directly accessible/modifiable from outside the class. Use appropriate accessor and mutator methods.
Your class must include the following methods:
initialiseAccount (accountNumber, password, branch, surnames, firstNames) to store initial values. toString () to display all information in the instance except the password and balance. withdrawCash (amount) to lower the account balance if there is money available and return 0. If there are insufficient funds the method must leave the balance unchanged and return -1. depositCash (amount) to increase the balance. changeUserPassword (oldPassword, newPassword) to change the password and return 0. If the old password does not match what is in the object, the method must return -1 and leave the password unchanged. Your Question2 driver class must first ask the user for account informatiom, then provide the user with an interactive menu to perform tasks as indicated in the sample output. The driver class must print out suitable messages as indicated.
Sample I/O
Enter Account Number102Enter Branch NameRondeboschEnter SurnamesMacGregorEnter First NamesKennethEnter your Account Passwordfoo------------Account Operation Menu----------0. Quit1. View account details2. Withdraw cash3. Deposit cash/cheque4. View balance5. Change user passwordEnter user operation number1Account Number: 102Branch: RondeboschName: Kenneth MacGregor------------Account Operation Menu----------0. Quit1. View account details2. Withdraw cash3. Deposit cash/cheque4. View balance5. Change user passwordEnter user operation number3Enter Amount to deposit2400Deposit successful------------Account Operation Menu----------0. Quit1. View account details2. Withdraw cash3. Deposit cash/cheque4. View balance5. Change user passwordEnter user operation number4Balance: R2400.00------------Account Operation Menu---------0. Quit1. View account details2. Withdraw cash3. Deposit cash/cheque4. View balance5. Change user passwordEnter user operation number2Enter amount to withdraw3500Insufficient funds------------Account Operation Menu---------0. Quit1. View account details2. Withdraw cash3. Deposit cash/cheque4. View balance5. Change user passwordEnter user operation number2Enter amount to withdraw500Withdrawal successful------------Account Operation Menu----------0. Quit1. View account details2. Withdraw cash3. Deposit cash/cheque4. View balance5. Change user passwordEnter user operation number4Balance: R1900.00------------Account Operation Menu----------0. Quit1. View account details2. Withdraw cash3. Deposit cash/cheque4. View balance5. Change user passwordEnter user operation number5Enter old passwordflaEnter new passwordbarOld password does not match------------Account Operation Menu----------0. Quit1. View account details2. Withdraw cash3. Deposit cash/cheque4. View balance5. Change user passwordEnter user operation number5Enter old passwordfooEnter new passwordbarPassword change successful------------Account Operation Menu----------0. Quit1. View account details2. Withdraw cash3. Deposit cash/cheque4. View balance5. Change user passwordEnter user operation number0Bye
View All Comments
| View Tutorial