11using System ;
22using System . Collections . Generic ;
3+ using System . Linq ;
34
4- namespace BankApp
5+ namespace BankApp ;
6+
7+ // TASK 2: Define Enum, Struct, and Record types
8+
9+ // TASK 2: Step 1 - Define the BankAccountType enum with Checking, Savings, and Business values
10+
11+ public enum BankAccountType
512{
6- // TASK 1: Define the AccountType enum
7- // TASK 1: Step 1 - Define the AccountType enum
8- public enum AccountType
9- {
10- Checking ,
11- Savings ,
12- Business
13- }
13+ Checking ,
14+ Savings ,
15+ Business
16+ }
1417
15- public static class AccountTypeExtensions
18+ // TASK 2: Step 2 - Define an extension method to provide descriptions for each BankAccountType value
19+ public static class BankAccountTypeExtensions
20+ {
21+ // TASK 1: Step 2 - Add an extension method to provide descriptions for each AccountType.
22+ public static string GetDescription ( this BankAccountType accountType )
1623 {
17- // TASK 1: Step 2 - Add an extension method to provide descriptions for each AccountType.
18- public static string GetDescription ( this AccountType accountType )
24+ return accountType switch
1925 {
20- return accountType switch
21- {
22- AccountType . Checking => "A standard checking account." ,
23- AccountType . Savings => "A savings account with interest." ,
24- AccountType . Business => "A business account for companies." ,
25- _ => "Unknown account type."
26- } ;
27- }
26+ BankAccountType . Checking => "A standard checking account." ,
27+ BankAccountType . Savings => "A savings account with interest." ,
28+ BankAccountType . Business => "A business account for companies." ,
29+ _ => "Unknown account type."
30+ } ;
2831 }
32+ }
2933
30- // TASK 2: Define the Transaction struct
31- // TASK 2: Step 1 - Define the Transaction struct
32- public readonly struct Transaction
34+ // TASK 2: Step 3 - Define the BankAccountNumber struct
35+ public readonly struct BankAccountNumber
36+ {
37+ public string Value { get ; }
38+ public BankAccountNumber ( string value )
3339 {
34- public double Amount { get ; }
35- public DateTime Date { get ; }
36- public string Description { get ; }
40+ // Simple format: 12 digits (demo-friendly)
41+ if ( value is null || value . Length != 12 || ! value . All ( char . IsDigit ) )
42+ throw new ArgumentException ( "Account numbers must be 12 digits." ) ;
43+ Value = value ;
44+ }
45+ public override string ToString ( ) => Value ;
46+ }
3747
38- public Transaction ( double amount , DateTime date , string description )
39- {
40- Amount = amount ;
41- Date = date ;
42- Description = description ;
43- }
48+ // TASK 2: Step 4 - Define the AccountHolderDetails record
49+ public record AccountHolderDetails ( string Name , string CustomerId , string Address ) ;
4450
45- public override string ToString ( )
46- {
47- return $ "{ Date . ToShortDateString ( ) } : { Description } - { Amount : C} ";
48- }
51+ // TASK 2: Step 5 - Define the Transaction record
52+ public record Transaction ( decimal Amount , DateTime Date , string Description )
53+ {
54+ public override string ToString ( )
55+ {
56+ return $ "{ Date . ToShortDateString ( ) } : { Description } - { Amount : C} ";
4957 }
58+ }
5059
51- // TASK 3: Define the Customer record
52- // TASK 3: Step 1 - Define the Customer record
53- public record Customer ( string Name , string CustomerId , string Address ) ;
5460
55- // TASK 4: Implement the BankAccount class
56- // TASK 4: Step 1 - Add properties for AccountNumber, Balance, AccountHolder, and Type.
57- public class BankAccount
58- {
59- public int AccountNumber { get ; }
60- public AccountType Type { get ; }
61- public Customer AccountHolder { get ; }
62- public double Balance { get ; private set ; }
61+ public class BankAccount
62+ {
63+ // TASK 3: Implement the BankAccount class
64+ // TASK 3: Step 1 - Add properties for BankAccountNumber, BankAccountType, Balance, AccountHolderDetails, and a Transactions list.
65+ public BankAccountNumber AccountNumber { get ; }
66+ public BankAccountType AccountType { get ; }
67+ public decimal Balance { get ; private set ; }
68+ public AccountHolderDetails AccountHolder { get ; }
69+ private List < Transaction > Transactions { get ; } = new ( ) ;
6370
64- // TASK 4: Step 2 - Add a constructor to initialize the properties.
65- public BankAccount ( int accountNumber , AccountType type , Customer accountHolder , double initialBalance = 0 )
66- {
67- AccountNumber = accountNumber ;
68- Type = type ;
69- AccountHolder = accountHolder ;
70- Balance = initialBalance ;
71- }
7271
73- // TASK 4: Step 3 - Add a method to deposit money into the account.
74- public void AddTransaction ( double amount , string description )
75- {
76- Balance += amount ;
77- Transactions . Add ( new Transaction ( amount , DateTime . Now , description ) ) ;
78- }
72+ // TASK 3: Step 2 - Add a constructor to initialize the properties.
73+ public BankAccount ( BankAccountNumber accountNumber , BankAccountType accountType , AccountHolderDetails accountHolder , decimal initialBalance = 0 )
74+ {
75+ AccountNumber = accountNumber ;
76+ AccountType = accountType ;
77+ AccountHolder = accountHolder ;
78+ Balance = initialBalance ;
79+ }
7980
80- // TASK 4: Step 4 - Add a method to withdraw money from the account.
81- public string DisplayAccountInfo ( )
82- {
83- return $ "Account Holder: { AccountHolder . Name } , Account Number: { AccountNumber } , Type: { Type } , Balance: { Balance : C} ";
84- }
81+ // TASK 3: Step 3 - Add a method for deposits/withdrawals that updates the balance and records the transaction.
82+ public void AddTransaction ( decimal amount , string description )
83+ {
84+ Balance += amount ;
85+ Transactions . Add ( new Transaction ( amount , DateTime . Now , description ) ) ;
86+ }
8587
86- // TASK 4: Step 5 - Add a method to display account information.
87- private List < Transaction > Transactions { get ; } = new ( ) ;
88+ // TASK 3: Step 4 - Add a method to display account information.
89+ public string DisplayAccountInfo ( )
90+ {
91+ return $ "Account Holder: { AccountHolder . Name } , Account Number: { AccountNumber } , Type: { AccountType } , Balance: { Balance : C} ";
92+ }
8893
89- // TASK 4: Step 6 - Add a list to track transactions.
90- public void DisplayTransactions ( )
94+ // TASK 3: Step 5 - Add a method to display transactions.
95+ public void DisplayTransactions ( )
96+ {
97+ Console . WriteLine ( "Transactions:" ) ;
98+ foreach ( var transaction in Transactions )
9199 {
92- Console . WriteLine ( "Transactions:" ) ;
93- foreach ( var transaction in Transactions )
94- {
95- Console . WriteLine ( transaction ) ;
96- }
100+ Console . WriteLine ( transaction ) ;
97101 }
98102 }
99- }
103+ }
0 commit comments