Skip to content

Commit f08eb4f

Browse files
author
Eric Camplin
committed
Implement Collection Types Code and Lab v1
1 parent f2db20e commit f08eb4f

34 files changed

+1348
-1267
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ 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
10-
IReadOnlyList<Transaction> Transactions { get; } // List of transactions for the account
119

12-
void Deposit(double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
13-
bool Withdraw(double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
14-
bool Transfer(IBankAccount targetAccount, double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
15-
void ApplyInterest(double years, DateOnly transactionDate, TimeOnly transactionTime, string description);
16-
void ApplyRefund(double refund, DateOnly transactionDate, TimeOnly transactionTime, string description);
17-
bool IssueCashiersCheck(double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
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);
1816
string DisplayAccountInfo();
19-
void AddTransaction(Transaction transaction);
20-
List<Transaction> GetAllTransactions();
2117
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,8 @@ public interface IBankCustomer
55
string FirstName { get; set; }
66
string LastName { get; set; }
77
string CustomerId { get; }
8-
IReadOnlyList<IBankAccount> Accounts { get; }
98

109
string ReturnFullName();
1110
void UpdateName(string firstName, string lastName);
1211
string DisplayCustomerInfo();
13-
bool IsPremiumCustomer();
14-
void ApplyBenefits();
15-
void AddAccount(IBankAccount account);
16-
void RemoveAccount(IBankAccount account);
17-
IEnumerable<IBankAccount> GetAllAccounts();
18-
IEnumerable<IBankAccount> GetAccountsByType(string accountType);
19-
}
12+
}

DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Solution/Interfaces/IMonthlyReportGenerator.cs

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

55
public interface IMonthlyReportGenerator
66
{
7-
void GenerateMonthlyReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
8-
void GenerateCurrentMonthToDateReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
9-
void GeneratePrevious30DayReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
10-
11-
}
7+
void GenerateMonthlyReport(); // Generates a report for a complete month
8+
void GenerateCurrentMonthToDateReport(); // Generates a report for the current month up to the current date
9+
void GeneratePrevious30DayReport(); // Generates a report for the previous 30 day period
10+
}

DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Solution/Interfaces/IQuarterlyReportGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ namespace Data_M2;
44

55
public interface IQuarterlyReportGenerator
66
{
7-
void GenerateQuarterlyReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
7+
void GenerateQuarterlyReport(); // Generates a report for a complete three-month period (Jan-Mar, Apr-Jun, Jul-Sep, Oct-Dec)
88
}

DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Solution/Interfaces/IYearlyReportGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Data_M2;
44

55
public interface IYearlyReportGenerator
66
{
7-
void GeneratePreviousYearReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
8-
void GenerateCurrentYearToDateReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
9-
void GenerateLast365DaysReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
7+
void GeneratePreviousYearReport(); // Generates a report for the previous year
8+
void GenerateCurrentYearToDateReport(); // Generates a report for the current year up to the current date
9+
void GenerateLast365DaysReport(); // Generates a report for the previous 365 days
1010
}

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

Lines changed: 27 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -3,130 +3,51 @@
33

44
namespace Data_M2;
55

6+
// TASK 2: Create Bank Class
7+
// Purpose: Manage customers and transaction reports.
8+
69
public class Bank
710
{
8-
// Fields
9-
private readonly Guid _bankId;
10-
private readonly List<BankCustomer> _customers;
11-
12-
// Properties
13-
public Guid BankId => _bankId;
14-
public IReadOnlyList<BankCustomer> Customers => _customers.AsReadOnly();
15-
16-
// Constructors
17-
public Bank()
18-
{
19-
_bankId = Guid.NewGuid();
20-
_customers = new List<BankCustomer>();
21-
}
22-
23-
// Methods
24-
internal IEnumerable<BankCustomer> GetAllCustomers()
25-
{
26-
return new List<BankCustomer>(_customers);
27-
}
28-
29-
internal IEnumerable<BankCustomer> GetCustomersByName(string firstName, string lastName)
30-
{
31-
List<BankCustomer> matchingCustomers = new List<BankCustomer>();
32-
foreach (var customer in _customers)
33-
{
34-
if (customer.FirstName.Equals(firstName, StringComparison.OrdinalIgnoreCase) &&
35-
customer.LastName.Equals(lastName, StringComparison.OrdinalIgnoreCase))
36-
{
37-
matchingCustomers.Add(customer);
38-
}
39-
}
40-
return matchingCustomers;
41-
}
11+
// TASK 2: Step 1 - Add Name and List<BankCustomer> properties
12+
public string Name { get; set; } // Removed 'required' keyword
13+
public List<BankCustomer> Customers { get; private set; }
4214

43-
// get customer based on Customer ID
44-
internal BankCustomer? GetCustomerById(string customerId)
45-
{
46-
foreach (var customer in _customers)
47-
{
48-
if (customer.CustomerId.Equals(customerId, StringComparison.OrdinalIgnoreCase))
49-
{
50-
return customer;
51-
}
52-
}
53-
return null;
54-
}
15+
// TASK 2: Step 2 - Add a Dictionary<string, List<Transaction>> for transaction reports
16+
public Dictionary<string, List<Transaction>> TransactionReports { get; private set; }
5517

56-
internal int GetNumberOfTransactions()
18+
// Constructor to initialize properties
19+
public Bank(string name)
5720
{
58-
int totalTransactions = 0;
59-
foreach (BankCustomer customer in _customers)
60-
{
61-
foreach (BankAccount account in customer.Accounts)
62-
{
63-
foreach (Transaction transaction in account.Transactions)
64-
{
65-
totalTransactions++;
66-
}
67-
}
68-
}
69-
return totalTransactions;
21+
Name = name; // Initialize the Name property
22+
Customers = new List<BankCustomer>();
23+
TransactionReports = new Dictionary<string, List<Transaction>>();
7024
}
7125

72-
internal double GetTotalMoneyInVault()
26+
// TASK 2: Step 3 - Implement AddCustomer method
27+
public void AddCustomer(BankCustomer customer)
7328
{
74-
double totalBankCash = 0;
75-
foreach (BankCustomer customer in _customers)
29+
if (customer != null && !Customers.Contains(customer))
7630
{
77-
foreach (BankAccount account in customer.Accounts)
78-
{
79-
totalBankCash += account.Balance;
80-
}
31+
Customers.Add(customer);
8132
}
82-
return totalBankCash;
8333
}
8434

85-
internal double GetDailyDeposits(DateOnly date)
86-
{
87-
double totalDailyDeposits = 0;
88-
foreach (BankCustomer customer in _customers)
89-
{
90-
foreach (BankAccount account in customer.Accounts)
91-
{
92-
foreach (Transaction transaction in account.Transactions)
93-
{
94-
if (transaction.TransactionDate == date && transaction.TransactionType == "Deposit")
95-
{
96-
totalDailyDeposits += transaction.TransactionAmount;
97-
}
98-
}
99-
}
100-
}
101-
return totalDailyDeposits;
102-
}
35+
// TASK 10: Add Dictionary for Reports
36+
// Purpose: Manage transaction data for reports in the Bank class.
10337

104-
internal double GetDailyWithdrawals(DateOnly date)
38+
// TASK 10: Step 1 - Add a method to add transactions to the dictionary
39+
public void AddTransactionToReport(string key, Transaction transaction)
10540
{
106-
double totalDailyWithdrawals = 0;
107-
foreach (BankCustomer customer in _customers)
41+
if (!TransactionReports.ContainsKey(key))
10842
{
109-
foreach (BankAccount account in customer.Accounts)
110-
{
111-
foreach (Transaction transaction in account.Transactions)
112-
{
113-
if (transaction.TransactionDate == date && transaction.TransactionType == "Withdraw")
114-
{
115-
totalDailyWithdrawals += transaction.TransactionAmount;
116-
}
117-
}
118-
}
43+
TransactionReports[key] = new List<Transaction>();
11944
}
120-
return totalDailyWithdrawals;
121-
}
122-
123-
internal void AddCustomer(BankCustomer customer)
124-
{
125-
_customers.Add(customer);
45+
TransactionReports[key].Add(transaction);
12646
}
12747

128-
internal void RemoveCustomer(BankCustomer customer)
48+
// TASK 10: Step 2 - Add a method to retrieve transactions for a specific key
49+
public List<Transaction> GetTransactionsForKey(string key)
12950
{
130-
_customers.Remove(customer);
51+
return TransactionReports.ContainsKey(key) ? TransactionReports[key] : new List<Transaction>();
13152
}
13253
}

0 commit comments

Comments
 (0)