11using System ;
2-
3- // TASK 4: Step 1 - Add System.Collections.Generic namespace
2+ using System . Collections . Generic ;
43
54namespace Data_M2 ;
65
76public class BankAccount : IBankAccount
87{
98 private static int s_nextAccountNumber ;
9+ protected double priorBalance ;
10+
11+ // Task 4: Step 3 - define a private readonly list to store transactions
12+
1013
1114 // Public read-only static properties
1215 public static double TransactionRate { get ; private set ; }
@@ -19,6 +22,10 @@ public class BankAccount : IBankAccount
1922 public double Balance { get ; internal set ; } = 0 ;
2023 public string AccountType { get ; set ; } = "Checking" ;
2124 public virtual double InterestRate { get ; protected set ; } // Virtual property to allow overriding in derived classes
25+ public BankCustomer Owner { get ; }
26+
27+ // Task 4: Step 4 - Add a readonly Transactions property
28+
2229
2330 static BankAccount ( )
2431 {
@@ -30,104 +37,134 @@ static BankAccount()
3037 MaxOverdraftFee = 10 ; // Maximum overdraft fee for an overdrawn checking account
3138 }
3239
33- public BankAccount ( string customerIdNumber , double balance = 200 , string accountType = "Checking" )
40+ public BankAccount ( BankCustomer owner , string customerIdNumber , double balance = 200 , string accountType = "Checking" )
3441 {
42+ Owner = owner ;
3543 this . AccountNumber = s_nextAccountNumber ++ ;
3644 this . CustomerId = customerIdNumber ;
3745 this . Balance = balance ;
3846 this . AccountType = accountType ;
47+
48+ // Task 4: Step 5a - Initialize the transactions list
49+
50+
3951 }
4052
4153 // Copy constructor for BankAccount
4254 public BankAccount ( BankAccount existingAccount )
4355 {
56+ Owner = existingAccount . Owner ;
57+
4458 this . AccountNumber = s_nextAccountNumber ++ ;
4559 this . CustomerId = existingAccount . CustomerId ;
4660 this . Balance = existingAccount . Balance ;
4761 this . AccountType = existingAccount . AccountType ;
48- }
4962
50- // TASK 4: Update BankAccount Class
51- // Purpose: Add Owner and Transactions properties for customer reference and transaction tracking.
63+ // Task 4: Step 5b - Initialize the transactions list
5264
53- // TASK 4: Step 2 - Add Owner property to reference BankCustomer
54- // Placeholder for adding a property to reference the owner of the account
5565
66+ }
67+
68+
69+ // TASK 4: Step 6 - Implement AddTransaction and GetAllTransactions methods
5670
57- // TASK 4: Step 3 - Add List<Transaction> property to track transactions
58- // Placeholder for adding a property to store a list of transactions
5971
6072
61- // TASK 4: Step 4 - Add methods to log transactions (e.g., AddTransaction)
62- // Placeholder for adding methods to log transactions
63-
6473 // Method to deposit money into the account
65- public void Deposit ( double amount )
74+ public virtual void Deposit ( double amount , DateOnly transactionDate , TimeOnly transactionTime , string description )
6675 {
6776 if ( amount > 0 )
6877 {
78+ priorBalance = Balance ;
6979 Balance += amount ;
70- // TASK 4: Step 4a - Add logic to log the deposit transaction
71- // Placeholder for logging the deposit transaction
80+ string transactionType = "Deposit" ;
81+ if ( description . Contains ( "-(TRANSFER)" ) )
82+ {
83+ transactionType = "Transfer" ;
84+ }
85+ else if ( description . Contains ( "-(BANK REFUND)" ) )
86+ {
87+ transactionType = "Bank Refund" ;
88+ }
89+
90+ // TASK 4: Step 7a - Add logic to log the deposit transaction
91+
92+
7293 }
7394 }
7495
7596 // Method to withdraw money from the account
76- public virtual bool Withdraw ( double amount )
97+ public virtual bool Withdraw ( double amount , DateOnly transactionDate , TimeOnly transactionTime , string description )
7798 {
7899 if ( amount > 0 && Balance >= amount )
79100 {
101+ priorBalance = Balance ;
80102 Balance -= amount ;
81- // TASK 4: Step 4b - Add logic to log the withdrawal transaction
82- // Placeholder for logging the withdrawal transaction
103+ string transactionType = "Withdraw" ;
104+ if ( description . Contains ( "-(TRANSFER)" ) )
105+ {
106+ transactionType = "Transfer" ;
107+ }
108+ else if ( description . Contains ( "-(BANK FEE)" ) )
109+ {
110+ transactionType = "Bank Fee" ;
111+ }
112+
113+ // TASK 4: Step 7b - Add logic to log the withdrawal transaction
114+
115+
83116 return true ;
84117 }
85118 return false ;
86119 }
87120
88121 // Method to transfer money to another account
89- public bool Transfer ( IBankAccount targetAccount , double amount )
122+ public virtual bool Transfer ( IBankAccount targetAccount , double amount , DateOnly transactionDate , TimeOnly transactionTime , string description )
90123 {
91- if ( Withdraw ( amount ) )
124+ description += "-(TRANSFER)" ;
125+ if ( Withdraw ( amount , transactionDate , transactionTime , description ) )
92126 {
93- targetAccount . Deposit ( amount ) ;
94- // TASK 4: Step 4c - Add logic to log the transfer transaction
95- // Placeholder for logging the transfer transaction
96-
127+ targetAccount . Deposit ( amount , transactionDate , transactionTime , description ) ;
97128 return true ;
98129 }
99130 return false ;
100131 }
101132
102133 // Method to apply interest
103- public void ApplyInterest ( double years )
134+ public virtual void ApplyInterest ( double years , DateOnly transactionDate , TimeOnly transactionTime , string description )
104135 {
136+ priorBalance = Balance ;
105137 double interest = AccountCalculations . CalculateCompoundInterest ( Balance , InterestRate , years ) ;
106138 Balance += interest ;
107- // TASK 4: Step 4d - Add logic to log the interest transaction
108- // Placeholder for logging the interest transaction
139+
140+ // TASK 4: Step 7d - Add logic to log the interest transaction
141+
109142
110143 }
111144
112145 // Method to apply refund
113- public void ApplyRefund ( double refund )
146+ public virtual void ApplyRefund ( double refund , DateOnly transactionDate , TimeOnly transactionTime , string description )
114147 {
148+ priorBalance = Balance ;
115149 Balance += refund ;
116- // TASK 4: Step 4e - Add logic to log the refund transaction
117- // Placeholder for logging the refund transaction
150+ // TASK 4: Step 7e - Add logic to log the refund transaction
151+
118152
119153 }
120154
121155 // Method to issue a cashier's check
122- public bool IssueCashiersCheck ( double amount )
156+ public virtual bool IssueCashiersCheck ( double amount , DateOnly transactionDate , TimeOnly transactionTime , string description )
123157 {
124158 if ( amount > 0 && Balance >= amount + BankAccount . MaxTransactionFee )
125159 {
160+ priorBalance = Balance ;
126161 Balance -= amount ;
127162 double fee = AccountCalculations . CalculateTransactionFee ( amount , BankAccount . TransactionRate , BankAccount . MaxTransactionFee ) ;
128163 Balance -= fee ;
129- // TASK 4: Step 4f - Add logic to log the cashier's check transaction
130- // Placeholder for logging the cashier's check and fee transactions
164+
165+ // TASK 4: Step 7f - Add logic to log the cashier's check transaction
166+
167+
131168 return true ;
132169 }
133170 return false ;
0 commit comments