Skip to content

Commit 76e86af

Browse files
committed
LP4 M2 - updated starter code files
1 parent cf9e509 commit 76e86af

File tree

6 files changed

+742
-646
lines changed

6 files changed

+742
-646
lines changed

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

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

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,101 @@ namespace Data_M2;
55
// TASK 5: Create Transaction Class
66
// Purpose: Represent deposits, withdrawals, and transfers.
77

8+
// TASK 5: Step 1 - Add properties for transaction details
9+
// Placeholder for adding properties to represent transaction details
10+
11+
// TASK 5: Step 2 - Add a constructor to initialize transaction details
12+
// Placeholder for adding a constructor to initialize the transaction
13+
14+
815
public class Transaction
916
{
10-
// TASK 5: Step 1 - Add properties for transaction details
11-
// Placeholder for adding properties to represent transaction details
17+
// private fields
18+
private readonly Guid transactionId;
19+
private readonly string transactionType;
20+
private readonly DateOnly transactionDate;
21+
private readonly TimeOnly transactionTime;
22+
private readonly double priorBalance;
23+
private readonly double transactionAmount;
24+
private readonly int sourceAccountNumber;
25+
private readonly int targetAccountNumber;
26+
private readonly string description;
27+
28+
// Gets the unique identifier for the transaction.
29+
public Guid TransactionId => transactionId;
30+
31+
// Gets or sets the type of the transaction (e.g., Withdraw, Deposit, Transfer, Bank Fee, Bank Refund).
32+
public string TransactionType => transactionType;
33+
34+
// Gets or sets the date of the transaction.
35+
public DateOnly TransactionDate => transactionDate;
36+
37+
// Gets or sets the time of the transaction.
38+
public TimeOnly TransactionTime => transactionTime;
39+
40+
// Gets the prior balance of the account before the transaction.
41+
public double PriorBalance => priorBalance;
42+
43+
// Gets or sets the amount of the transaction.
44+
public double TransactionAmount => transactionAmount;
45+
46+
// Gets or sets the source bank account number for the transaction.
47+
public int SourceAccountNumber => sourceAccountNumber;
48+
49+
// Gets or sets the target bank account number for the transaction.
50+
public int TargetAccountNumber => targetAccountNumber;
51+
52+
// Gets or sets the description of the transaction.
53+
public string Description => description;
54+
55+
// constructors
56+
public Transaction(DateOnly date, TimeOnly time, double balance, double amount, int sourceAccountNum, int targetAccountNum, string typeOfTransaction, string descriptionMessage = "")
57+
{
58+
transactionId = Guid.NewGuid();
59+
transactionDate = date;
60+
transactionTime = time;
61+
priorBalance = balance;
62+
transactionAmount = amount;
63+
sourceAccountNumber = sourceAccountNum;
64+
targetAccountNumber = targetAccountNum;
65+
transactionType = typeOfTransaction;
66+
description = descriptionMessage;
67+
}
68+
69+
// Determines whether the transaction is valid based on its type and details.
70+
public bool IsValidTransaction()
71+
{
72+
// Check for valid Withdraw transaction
73+
if (transactionAmount <= 0 && sourceAccountNumber == targetAccountNumber && transactionType == "Withdraw")
74+
{
75+
return true;
76+
}
77+
// Check for valid Deposit transaction
78+
else if (transactionAmount > 0 && sourceAccountNumber == targetAccountNumber && transactionType == "Deposit")
79+
{
80+
return true;
81+
}
82+
// Check for valid Transfer transaction
83+
else if (transactionAmount > 0 && sourceAccountNumber != targetAccountNumber && transactionType == "Transfer")
84+
{
85+
return true;
86+
}
87+
// Check for bank fees transaction
88+
else if (transactionAmount < 0 && sourceAccountNumber == targetAccountNumber && transactionType == "Bank Fee")
89+
{
90+
return true;
91+
}
92+
// Check for bank refund transaction
93+
else if (transactionAmount > 0 && sourceAccountNumber == targetAccountNumber && transactionType == "Bank Refund")
94+
{
95+
return true;
96+
}
97+
return false;
98+
}
1299

13-
// TASK 5: Step 2 - Add a constructor to initialize transaction details
14-
// Placeholder for adding a constructor to initialize the transaction
15-
}
100+
// Returns a formatted string with transaction details for logging.
101+
public string ReturnTransaction()
102+
{
103+
return $"Transaction ID: {transactionId}, Type: {transactionType}, Date: {transactionDate}, Time: {transactionTime}, Prior Balance: {PriorBalance:C} Amount: {transactionAmount:C}, Source Account: {sourceAccountNumber}, Target Account: {targetAccountNumber}, Description: {description}";
104+
}
105+
}

DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Starter/Program.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,5 @@ static void Main()
9999
// TASK 10: Step 2 - Retrieve and display transactions from the dictionary
100100
// Placeholder for retrieving and displaying transactions from the dictionary
101101

102-
103-
// Example: Create a BankCustomer and display their information
104-
// BankCustomer exampleCustomer = new BankCustomer("Isabel", "Robledo");
105-
// Console.WriteLine($"Example Customer Created: {exampleCustomer.FirstName} {exampleCustomer.LastName}");
106-
107-
// Example: Use a method of the BankCustomer class
108-
// exampleCustomer.AddAccount(new BankAccount(exampleCustomer.CustomerId, 1000.00, "Savings"));
109-
// Console.WriteLine($"Account added for {exampleCustomer.FirstName} with balance: {exampleCustomer.Accounts[0].Balance}");
110102
}
111103
}

0 commit comments

Comments
 (0)