Skip to content

Commit 138bf65

Browse files
author
Eric Camplin
committed
Replace LP4 M1 Starter w LP3 M2 Solution
From zip - updated namespaces, using/, .sln to Data_M1
1 parent 2d80b96 commit 138bf65

File tree

12 files changed

+185
-165
lines changed

12 files changed

+185
-165
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@ public interface IBankCustomer
99
string ReturnFullName();
1010
void UpdateName(string firstName, string lastName);
1111
string DisplayCustomerInfo();
12-
bool IsPremiumCustomer();
13-
void ApplyBenefits();
1412
}

DownloadableCodeProjects/LP4_manage-app-data/Data_M1/Starter/Interfaces/IMonthlyReportGenerator.cs

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

55
public interface IMonthlyReportGenerator
66
{
7-
void GenerateMonthlyReport();
8-
void GenerateCurrentMonthToDateReport();
9-
void GeneratePrevious30DayReport();
10-
}
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_M1/Starter/Interfaces/IQuarterlyReportGenerator.cs

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

55
public interface IQuarterlyReportGenerator
66
{
7-
void GenerateQuarterlyReport();
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_M1/Starter/Interfaces/IYearlyReportGenerator.cs

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

55
public interface IYearlyReportGenerator
66
{
7-
void GeneratePreviousYearReport();
8-
void GenerateCurrentYearToDateReport();
9-
void GenerateLast365DaysReport();
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_M1/Starter/Models/BankAccount.cs

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ public class BankAccount : IBankAccount
77
private static int s_nextAccountNumber;
88

99
// Public read-only static properties
10-
public static double TransactionRate { get; protected set; }
11-
public static double MaxTransactionFee { get; protected set; }
12-
public static double OverdraftRate { get; protected set; }
13-
public static double MaxOverdraftFee { get; protected set; }
10+
public static double TransactionRate { get; private set; }
11+
public static double MaxTransactionFee { get; private set; }
12+
public static double OverdraftRate { get; private set; }
13+
public static double MaxOverdraftFee { get; private set; }
1414

1515
public int AccountNumber { get; }
1616
public string CustomerId { get; }
1717
public double Balance { get; internal set; } = 0;
1818
public string AccountType { get; set; } = "Checking";
19-
2019
public virtual double InterestRate { get; protected set; } // Virtual property to allow overriding in derived classes
2120

2221
static BankAccount()
@@ -35,7 +34,6 @@ public BankAccount(string customerIdNumber, double balance = 200, string account
3534
this.CustomerId = customerIdNumber;
3635
this.Balance = balance;
3736
this.AccountType = accountType;
38-
3937
}
4038

4139
// Copy constructor for BankAccount
@@ -48,7 +46,7 @@ public BankAccount(BankAccount existingAccount)
4846
}
4947

5048
// Method to deposit money into the account
51-
public virtual void Deposit(double amount)
49+
public void Deposit(double amount)
5250
{
5351
if (amount > 0)
5452
{
@@ -68,7 +66,7 @@ public virtual bool Withdraw(double amount)
6866
}
6967

7068
// Method to transfer money to another account
71-
public virtual bool Transfer(IBankAccount targetAccount, double amount)
69+
public bool Transfer(IBankAccount targetAccount, double amount)
7270
{
7371
if (Withdraw(amount))
7472
{
@@ -79,19 +77,19 @@ public virtual bool Transfer(IBankAccount targetAccount, double amount)
7977
}
8078

8179
// Method to apply interest
82-
public virtual void ApplyInterest(double years)
80+
public void ApplyInterest(double years)
8381
{
8482
Balance += AccountCalculations.CalculateCompoundInterest(Balance, InterestRate, years);
8583
}
8684

8785
// Method to apply refund
88-
public virtual void ApplyRefund(double refund)
86+
public void ApplyRefund(double refund)
8987
{
9088
Balance += refund;
9189
}
9290

9391
// Method to issue a cashier's check
94-
public virtual bool IssueCashiersCheck(double amount)
92+
public bool IssueCashiersCheck(double amount)
9593
{
9694
if (amount > 0 && Balance >= amount + BankAccount.MaxTransactionFee)
9795
{
@@ -105,20 +103,6 @@ public virtual bool IssueCashiersCheck(double amount)
105103
// Method to display account information
106104
public virtual string DisplayAccountInfo()
107105
{
108-
return $"Account Number: {AccountNumber}, Type: {AccountType}, Balance: {Balance}, Interest Rate: {InterestRate}, Customer ID: {CustomerId}";
106+
return $"Account Number: {AccountNumber}, Type: {AccountType}, Balance: {Balance:C}, Interest Rate: {InterestRate:P}, Customer ID: {CustomerId}";
109107
}
110108
}
111-
112-
// Summary of Changes:
113-
//
114-
// - Marked BankAccount as abstract.
115-
// - Made methods virtual: Deposit, Withdraw, Transfer, ApplyInterest, ApplyRefund, IssueCashiersCheck, and DisplayAccountInfo.
116-
//
117-
// These changes allow derived classes to override these methods and provide specific implementations. Now you can create derived classes like CheckingAccount, SavingsAccount, MoneyMarketAccount, and CertificateOfDeposit with their specific behaviors.
118-
119-
120-
// Step 3: Demonstrate the derived classes in Program.cs
121-
122-
123-
124-

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace Data_M1;
44

5-
public abstract partial class BankCustomer : IBankCustomer
5+
public partial class BankCustomer : IBankCustomer
66
{
77
private static int s_nextCustomerId;
88
private string _firstName = "Tim";
99
private string _lastName = "Shao";
10-
1110
public string CustomerId { get; }
1211

1312
public string FirstName

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Data_M1;
44

5-
public abstract partial class BankCustomer : IBankCustomer
5+
public partial class BankCustomer : IBankCustomer
66
{
77
// Method to return the full name of the customer
88
public string ReturnFullName()
@@ -22,9 +22,4 @@ public string DisplayCustomerInfo()
2222
{
2323
return $"Customer ID: {CustomerId}, Name: {ReturnFullName()}";
2424
}
25-
26-
public abstract bool IsPremiumCustomer();
27-
28-
public abstract void ApplyBenefits();
29-
3025
}

DownloadableCodeProjects/LP4_manage-app-data/Data_M1/Starter/Models/CheckingAccount.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,41 @@ namespace Data_M1;
44

55
public class CheckingAccount : BankAccount
66
{
7-
public double OverdraftLimit { get; set; }
8-
7+
// public static properties with private setters for default overdraft limit and default interest rate
98
public static double DefaultOverdraftLimit { get; private set; }
109
public static double DefaultInterestRate { get; private set; }
1110

11+
// public property for overdraft limit
12+
public double OverdraftLimit { get; set; }
13+
1214
static CheckingAccount()
1315
{
1416
DefaultOverdraftLimit = 500;
15-
DefaultInterestRate = 0.00;
17+
DefaultInterestRate = 0.0;
1618
}
1719

1820
public CheckingAccount(string customerIdNumber, double balance = 200, double overdraftLimit = 500)
1921
: base(customerIdNumber, balance, "Checking")
2022
{
2123
OverdraftLimit = overdraftLimit;
22-
}
2324

24-
public override double InterestRate
25-
{
26-
get { return DefaultInterestRate; }
27-
protected set { DefaultInterestRate = value; }
2825
}
2926

3027
public override bool Withdraw(double amount)
3128
{
3229
if (amount > 0 && Balance + OverdraftLimit >= amount)
3330
{
34-
// Call the base class Withdraw method
35-
bool result = base.Withdraw(amount);
31+
Balance -= amount;
3632

37-
// Additional logic for CheckingAccount
38-
if (result && Balance < 0)
33+
// Check if the account is overdrawn
34+
if (Balance < 0)
3935
{
4036
double overdraftFee = AccountCalculations.CalculateOverdraftFee(Math.Abs(Balance), BankAccount.OverdraftRate, BankAccount.MaxOverdraftFee);
4137
Balance -= overdraftFee;
4238
Console.WriteLine($"Overdraft fee of ${overdraftFee} applied.");
4339
}
4440

45-
return result;
41+
return true;
4642
}
4743
return false;
4844
}
@@ -51,4 +47,10 @@ public override string DisplayAccountInfo()
5147
{
5248
return base.DisplayAccountInfo() + $", Overdraft Limit: {OverdraftLimit}";
5349
}
50+
51+
public override double InterestRate
52+
{
53+
get { return DefaultInterestRate; }
54+
protected set { DefaultInterestRate = value; }
55+
}
5456
}

DownloadableCodeProjects/LP4_manage-app-data/Data_M1/Starter/Models/MoneyMarketAccount.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ namespace Data_M1;
44

55
public class MoneyMarketAccount : BankAccount
66
{
7-
public double MinimumBalance { get; set; }
8-
public double MinimumOpeningBalance { get; set; }
9-
7+
// public static properties with private setters for default interest rate, default minimum balance, and default minimum opening balance
108
public static double DefaultInterestRate { get; private set; }
119
public static double DefaultMinimumBalance { get; private set; }
1210
public static double DefaultMinimumOpeningBalance { get; private set; }
1311

12+
// public property for minimum balance and minimum opening balance
13+
public double MinimumBalance { get; set; }
14+
public double MinimumOpeningBalance { get; set; }
15+
1416
static MoneyMarketAccount()
1517
{
1618
DefaultInterestRate = 0.04; // 4 percent interest rate
@@ -30,12 +32,6 @@ public MoneyMarketAccount(string customerIdNumber, double balance = 2000, double
3032
MinimumOpeningBalance = DefaultMinimumOpeningBalance; // Set the minimum opening balance to the default value
3133
}
3234

33-
public override double InterestRate
34-
{
35-
get { return DefaultInterestRate; }
36-
protected set { DefaultInterestRate = value; }
37-
}
38-
3935
public override bool Withdraw(double amount)
4036
{
4137
if (amount > 0 && Balance - amount >= MinimumBalance)
@@ -46,8 +42,14 @@ public override bool Withdraw(double amount)
4642
return false;
4743
}
4844

45+
public override double InterestRate
46+
{
47+
get { return DefaultInterestRate; }
48+
protected set { DefaultInterestRate = value; }
49+
}
50+
4951
public override string DisplayAccountInfo()
5052
{
51-
return base.DisplayAccountInfo() + $", Minimum Balance: {MinimumBalance}, Interest Rate: {InterestRate * 100}%, Minimum Opening Balance: {MinimumOpeningBalance}";
53+
return base.DisplayAccountInfo() + $", Minimum Balance: {MinimumBalance}, Minimum Opening Balance: {MinimumOpeningBalance}";
5254
}
5355
}

DownloadableCodeProjects/LP4_manage-app-data/Data_M1/Starter/Models/SavingsAccount.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ namespace Data_M1;
44

55
public class SavingsAccount : BankAccount
66
{
7-
public int WithdrawalLimit { get; set; }
7+
// private field to track the number of withdrawals this month
88
private int _withdrawalsThisMonth;
9-
public double MinimumOpeningBalance { get; set; }
109

10+
// public static properties with private setters for default withdrawal limit, default minimum opening balance, and default interest rate
1111
public static int DefaultWithdrawalLimit { get; private set; }
1212
public static double DefaultMinimumOpeningBalance { get; private set; }
1313
public static double DefaultInterestRate { get; private set; }
1414

15+
// public property for withdrawal limit and minimum opening balance
16+
public int WithdrawalLimit { get; set; }
17+
public double MinimumOpeningBalance { get; set; }
18+
1519
static SavingsAccount()
1620
{
1721
DefaultWithdrawalLimit = 6;
@@ -32,12 +36,6 @@ public SavingsAccount(string customerIdNumber, double balance = 500, int withdra
3236
MinimumOpeningBalance = DefaultMinimumOpeningBalance; // Set the minimum opening balance to the default value
3337
}
3438

35-
public override double InterestRate
36-
{
37-
get { return DefaultInterestRate; }
38-
protected set { DefaultInterestRate = value; }
39-
}
40-
4139
public override bool Withdraw(double amount)
4240
{
4341
if (amount > 0 && Balance >= amount && _withdrawalsThisMonth < WithdrawalLimit)
@@ -54,6 +52,12 @@ public void ResetWithdrawalLimit()
5452
_withdrawalsThisMonth = 0;
5553
}
5654

55+
public override double InterestRate
56+
{
57+
get { return DefaultInterestRate; }
58+
protected set { DefaultInterestRate = value; }
59+
}
60+
5761
public override string DisplayAccountInfo()
5862
{
5963
return base.DisplayAccountInfo() + $", Withdrawal Limit: {WithdrawalLimit}, Withdrawals This Month: {_withdrawalsThisMonth}";

0 commit comments

Comments
 (0)