Exported from Notepad++
1 // Name: Mostapha Abdelaziz
2 // Class: CST8132 #303
3 //
4 // Assessment: Lab 6
5 // Description: Interface to be implemented by BankAccount
6
7
8 package Banking;
9
10 /**
11 * The banking interface to be implemented by the Bank Account class.
12 * @author Mostapha Abdelaziz
13 * @version 1.0
14 * @since 1.8
15 */
16 public interface BankSimulator {
17 //abstract methods for implementation
18 /**
19 * Return a formatted string of all the account information.
20 * @return The formatted string of all information
21 */
22 public String toString();
23
24 /**
25 * Take input from the user and create a new Bank Account.
26 * @return A boolean value of whether it was successful or not.
27 */
28 public boolean addBankAccount();
29
30 /**
31 * Update the balance of the account based on a withdrawal or a deposit.
32 * @param The amount withdrawn or deposited.
33 */
34 public void updateBalance(double change);
35
36 }
37
Exported from Notepad++
1 // Name: Mostapha Abdelaziz
2 // Class: CST8132 #303
3 //
4 // Assessment: Lab 6
5 // Description: Abstract class to be used as the basis for savings and chequing accounts
6
7 package Banking;
8 import java.text.DecimalFormat;
9
10 /**
11 * Bank account class to be extended by savings and chequing accounts.
12 * Contains the common attributes and behaviours.
13 * @author Mostapha Abdelaziz
14 * @version 1.0
15 * @since 1.8
16 */
17 abstract class BankAccount implements BankSimulator {
18 // instance variables
19 /** The bank account number, up to 8 digits **/
20 protected long accountNumber;
21 /** The account holder, an object of class Person **/
22 protected Person accHolder = new Person();
23 /** The balance of amount of funds available in the account **/
24 protected double balance;
25
26 // no argument constructor
27 /**
28 * No argument constructor to create a bank account without parameters.
29 */
30 BankAccount() {
31
32 }
33
34
35 //return the data of the account
36 /**
37 * Return a formatted string of all the account information.
38 * @return The formatted string of all information
39 */
40 public String toString() {
41 //for formatting balance
42 DecimalFormat format = new DecimalFormat("0.##");
43
44 //add all the details to one string
45 String details;
46 details = "AccountNumber: " +accountNumber+ " | Name: " +accHolder.getName()+
47 " | Phone Number: " +accHolder.getPhoneNumber()+
48 " | Email Address: " +accHolder.getEmail()+
49 " | Balance: " +format.format(balance);
50
51 //return string
52 return details;
53 }
54
55 //method for adding a bank account to the array
56 /**
57 * Take input from the user and create a new Bank Account.
58 * @return A boolean value of whether it was successful or not.
59 */
60 public boolean addBankAccount() {
61 // ask for and store input to create a new account
62 //account details
63 System.out.print("Enter account number (up to 8 digits) : ");
64 accountNumber = Validate.iLong("Invalid account Number, try again : " , 0, 99999999);
65
66 // account holder details
67 System.out.print("Enter first name of account holder : ");
68 accHolder.setFirstName(Validate.iString("Invalid Name, try again : ", "`","~","1","2","3","4","5",
69 "6","7","8","9","0","_","=","+","!","@","#","$","%","^","&","*","(",")",";",":","[",
70 "]","{","}","|","\\","\"",",",".","/","<",">","?"));
71
72 System.out.print("Enter last name of account holder : ");
73 accHolder.setLastName(Validate.iString("Invalid Name, try again : ", "`","~","1","2","3","4","5",
74 "6","7","8","9","0","_","=","+","!","@","#","$","%","^","&","*","(",")",";",":","[",
75 "]","{","}","|","\\","\"",",",".","/","<",">","?"));
76
77 System.out.print("Enter phone number of account holder : ");
78 accHolder.setPhoneNumber(Validate.iLong("Invalid Phone Number, try again : "
79 , 1000000000L, 9999999999L));
80
81 System.out.print("Enter email of account holder : ");
82 accHolder.setEmail(Validate.iString());
83
84 System.out.print("Enter opening balance of account holder : ");
85 balance = Validate.iDouble("Invalid balance, try again : ", 0);
86
87 // return boolean value to be used next lab
88 return false;
89 }
90
91 //withdraw or deposit from the account
92 /**
93 * Update the balance of the account based on a withdrawal or a deposit.
94 * @param The amount withdrawn or deposited.
95 */
96 public void updateBalance(double changes) {
97 //add or subtract from current balance
98 balance = balance + changes;
99 }
100
101 //abstract to be used in sub classes
102 /**
103 * Perform the necessary calculations for any monthly fees or interest.
104 */
105 public abstract void monthlyAccountUpdate();
106 }
107