Skip to content

Commit c9600e2

Browse files
committed
LP4 M2 - updates starter code and instructions
1 parent 3225377 commit c9600e2

7 files changed

Lines changed: 325 additions & 142 deletions

File tree

DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Starter/Interfaces/IBankAccount.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ public interface IBankAccount
66
string CustomerId { get; }
77
double Balance { get; }
88
string AccountType { get; }
9+
BankCustomer Owner { get; } // This is the BankCustomer object that owns the account
910

10-
void Deposit(double amount);
11-
bool Withdraw(double amount);
12-
bool Transfer(IBankAccount targetAccount, double amount);
13-
void ApplyInterest(double years);
14-
void ApplyRefund(double refund);
15-
bool IssueCashiersCheck(double amount);
11+
// Task 4: Step 1 - Add Transactions property
12+
13+
14+
void Deposit(double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
15+
bool Withdraw(double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
16+
bool Transfer(IBankAccount targetAccount, double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
17+
void ApplyInterest(double years, DateOnly transactionDate, TimeOnly transactionTime, string description);
18+
void ApplyRefund(double refund, DateOnly transactionDate, TimeOnly transactionTime, string description);
19+
bool IssueCashiersCheck(double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
1620
string DisplayAccountInfo();
21+
22+
// Task 4: Step 2 - Add methods to log and retrieve transactions
23+
24+
1725
}

DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Starter/Interfaces/IBankCustomer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ public interface IBankCustomer
77
string CustomerId { get; }
88

99
// TASK 3: Step 1 - Expose Accounts property
10-
//IReadOnlyList<IBankAccount> Accounts { get; }
10+
1111

1212
string ReturnFullName();
1313
void UpdateName(string firstName, string lastName);
1414
string DisplayCustomerInfo();
1515

1616
// TASK 3: Step 2 - Add account-management methods
17-
//void AddAccount(IBankAccount account);
17+
1818

1919
// Task 3: Steps 3 - 6 should be completed in BankCustomer.cs
2020
}

DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Starter/Models/Bank.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ namespace Data_M2;
88

99
public class Bank
1010
{
11-
// TASK 2: Step 1 - Add Name and List<BankCustomer> properties
12-
// Placeholder for Name and Customers properties
11+
// TASK 2: Step 1 - Add bank's unique identifier and customers list
1312

14-
// TASK 2: Step 2 - Add a Dictionary<string, List<Transaction>> for transaction reports
15-
// Placeholder for TransactionReports property
1613

17-
// Constructor to initialize properties
18-
// Placeholder for constructor
14+
// TASK 2: Step 2 - Add constructor to initialize properties
15+
1916

2017
// TASK 2: Step 3 - Implement AddCustomer method
21-
// Placeholder for AddCustomer method
18+
2219

2320
// TASK 10: Add Dictionary for Reports
2421
// Purpose: Manage transaction data for reports in the Bank class.

DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Starter/Models/BankAccount.cs

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
using System;
2-
3-
// TASK 4: Step 1 - Add System.Collections.Generic namespace
2+
using System.Collections.Generic;
43

54
namespace Data_M2;
65

76
public 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;

DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Starter/Models/BankCustomer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class BankCustomer : IBankCustomer
1212
private string _lastName = "Shao";
1313

1414
// TASK 3: Step 3 - declare the Accounts field
15-
//private readonly List<IBankAccount> _accounts;
15+
1616

1717
public string CustomerId { get; }
1818

@@ -30,7 +30,7 @@ public string LastName
3030

3131

3232
// TASK 3: Step 4 - expose the Accounts property
33-
// public IReadOnlyList<IBankAccount> Accounts => _accounts.AsReadOnly();
33+
3434

3535
static BankCustomer()
3636
{
@@ -45,7 +45,7 @@ public BankCustomer(string firstName, string lastName)
4545
this.CustomerId = (s_nextCustomerId++).ToString("D10");
4646

4747
// TASK 3: Step 5 - initialize the Accounts field
48-
//_accounts = new List<IBankAccount>();
48+
4949
}
5050

5151
// Copy constructor for BankCustomer
@@ -56,7 +56,7 @@ public BankCustomer(BankCustomer existingCustomer)
5656
this.CustomerId = (s_nextCustomerId++).ToString("D10");
5757

5858
// TASK 3: Step 6 - initialize the Accounts field by copying from existingCustomer
59-
//_accounts = new List<IBankAccount>(existingCustomer._accounts);
59+
6060
}
6161

6262
// TASK 3: Step 7 - should be completed in BankCustomerMethods.cs

DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Starter/Models/BankCustomerMethods.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,5 @@ public string DisplayCustomerInfo()
2424
}
2525

2626
// Task 3: Step 7 - Add account-management methods
27-
//public void AddAccount(IBankAccount account)
28-
//{
29-
// _accounts.Add(account);
30-
//}
27+
3128
}

0 commit comments

Comments
 (0)