diff --git a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/BankAccount.cs b/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/BankAccount.cs deleted file mode 100644 index c41fa0e1ff61a..0000000000000 --- a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/BankAccount.cs +++ /dev/null @@ -1,180 +0,0 @@ -namespace OOProgramming; - -/// -/// Represents a bank account with basic banking operations including deposits, withdrawals, and transaction history. -/// Supports minimum balance constraints and provides extensible month-end processing capabilities. -/// -public class BankAccount -{ - /// - /// Gets the unique account number for this bank account. - /// - /// A string representation of the account number, generated sequentially. - public string Number { get; } - - /// - /// Gets or sets the name of the account owner. - /// - /// The full name of the person who owns this account. - public string Owner { get; set; } - - /// - /// Gets the current balance of the account by calculating the sum of all transactions. - /// - /// The current account balance as a decimal value. - public decimal Balance => _allTransactions.Sum(i => i.Amount); - - private static int s_accountNumberSeed = 1234567890; - - private readonly decimal _minimumBalance; - - /// - /// Initializes a new instance of the BankAccount class with the specified owner name and initial balance. - /// Uses a default minimum balance of 0. - /// - /// The name of the account owner. - /// The initial deposit amount for the account. - /// - /// This constructor is a convenience overload that calls the main constructor with a minimum balance of 0. - /// If the initial balance is greater than 0, it will be recorded as the first transaction with the note "Initial balance". - /// The account number is automatically generated using a static seed value that increments for each new account. - /// - public BankAccount(string name, decimal initialBalance) : this(name, initialBalance, 0) { } - - /// - /// Initializes a new instance of the BankAccount class with the specified owner name, initial balance, and minimum balance constraint. - /// - /// The name of the account owner. - /// The initial deposit amount for the account. - /// The minimum balance that must be maintained in the account. - /// - /// This is the primary constructor that sets up all account properties. The account number is generated automatically - /// using a static seed value. If an initial balance is provided and is greater than 0, it will be added as the first - /// transaction. The minimum balance constraint will be enforced on all future withdrawal operations through the - /// method. - /// - public BankAccount(string name, decimal initialBalance, decimal minimumBalance) - { - Number = s_accountNumberSeed.ToString(); - s_accountNumberSeed++; - - Owner = name; - _minimumBalance = minimumBalance; - if (initialBalance > 0) - MakeDeposit(initialBalance, DateTime.Now, "Initial balance"); - } - - private readonly List _allTransactions = []; - - /// - /// Makes a deposit to the account by adding a positive transaction. - /// - /// The amount to deposit. Must be positive. - /// The date when the deposit is made. - /// A descriptive note about the deposit transaction. - /// Thrown when the deposit amount is zero or negative. - /// - /// This method creates a new object with the specified amount, date, and note, - /// then adds it to the internal transaction list. The transaction amount must be positive - negative amounts - /// are not allowed for deposits. The account balance is automatically updated through the Balance property - /// which calculates the sum of all transactions. There are no limits or restrictions on deposit amounts. - /// - public void MakeDeposit(decimal amount, DateTime date, string note) - { - if (amount <= 0) - { - throw new ArgumentOutOfRangeException(nameof(amount), "Amount of deposit must be positive"); - } - var deposit = new Transaction(amount, date, note); - _allTransactions.Add(deposit); - } - - /// - /// Makes a withdrawal from the account by adding a negative transaction. - /// Checks withdrawal limits and minimum balance constraints before processing. - /// - /// The amount to withdraw. Must be positive. - /// The date when the withdrawal is made. - /// A descriptive note about the withdrawal transaction. - /// Thrown when the withdrawal amount is zero or negative. - /// Thrown when the withdrawal would cause the balance to fall below the minimum balance. - /// - /// This method first validates that the withdrawal amount is positive, then checks if the withdrawal would - /// violate the minimum balance constraint by calling . The withdrawal is - /// recorded as a negative transaction amount. If the withdrawal limit check returns an overdraft transaction - /// (such as a fee), that transaction is also added to the account. The method enforces business rules through - /// the virtual CheckWithdrawalLimit method, allowing derived classes to implement different withdrawal policies. - /// - public void MakeWithdrawal(decimal amount, DateTime date, string note) - { - if (amount <= 0) - { - throw new ArgumentOutOfRangeException(nameof(amount), "Amount of withdrawal must be positive"); - } - Transaction? overdraftTransaction = CheckWithdrawalLimit(Balance - amount < _minimumBalance); - Transaction? withdrawal = new(-amount, date, note); - _allTransactions.Add(withdrawal); - if (overdraftTransaction != null) - _allTransactions.Add(overdraftTransaction); - } - - /// - /// Checks whether a withdrawal would violate the account's minimum balance constraint. - /// This method can be overridden in derived classes to implement different withdrawal limit policies. - /// - /// True if the withdrawal would cause the balance to fall below the minimum balance. - /// A Transaction object representing any overdraft fees or penalties, or null if no additional charges apply. - /// Thrown when the withdrawal would cause an overdraft and the account type doesn't allow it. - protected virtual Transaction? CheckWithdrawalLimit(bool isOverdrawn) - { - if (isOverdrawn) - { - throw new InvalidOperationException("Not sufficient funds for this withdrawal"); - } - else - { - return default; - } - } - - /// - /// Generates a detailed account history report showing all transactions with running balance calculations. - /// - /// A formatted string containing the complete transaction history with dates, amounts, running balances, and notes. - /// - /// This method creates a formatted report that includes a header row followed by all transactions in chronological order. - /// Each row shows the transaction date (in short date format), the transaction amount, the running balance after that - /// transaction, and any notes associated with the transaction. The running balance is calculated by iterating through - /// all transactions and maintaining a cumulative total. The report uses tab characters for column separation and - /// is suitable for display in console applications or simple text outputs. - /// - public string GetAccountHistory() - { - var report = new System.Text.StringBuilder(); - - decimal balance = 0; - report.AppendLine("Date\t\tAmount\tBalance\tNote"); - foreach (var item in _allTransactions) - { - balance += item.Amount; - report.AppendLine($"{item.Date.ToShortDateString()}\t{item.Amount}\t{balance}\t{item.Notes}"); - } - - return report.ToString(); - } - - // Added for OO tutorial: - - /// - /// Performs month-end processing for the account. This virtual method can be overridden in derived classes - /// to implement specific month-end behaviors such as interest calculations, fee assessments, or statement generation. - /// - /// - /// The base implementation of this method does nothing, providing a safe default for basic bank accounts. - /// Derived classes such as savings accounts or checking accounts can override this method to implement - /// account-specific month-end processing. Examples include calculating and applying interest payments, - /// assessing monthly maintenance fees, generating account statements, or performing regulatory compliance checks. - /// This method is typically called by banking systems at the end of each month as part of batch processing operations. - /// - public virtual void PerformMonthEndTransactions() { } -} diff --git a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/GiftCardAccount.cs b/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/GiftCardAccount.cs deleted file mode 100644 index 9ec4f25976d95..0000000000000 --- a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/GiftCardAccount.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace OOProgramming; - -/// -/// Represents a gift card account that extends with optional recurring monthly deposits. -/// Designed for prepaid gift cards that can optionally receive automatic monthly top-ups. -/// -/// -/// A gift card account is a specialized prepaid account that can be loaded with an initial balance and optionally -/// configured to receive automatic monthly deposits. This account type is ideal for gift cards, allowances, or -/// subscription-based funding scenarios. The account uses the standard minimum balance of $0 from the base -/// class, preventing overdrafts while allowing the balance to reach zero. -/// Monthly deposits, when configured, provide a convenient way to automatically replenish the account balance. -/// -public class GiftCardAccount : BankAccount -{ - private readonly decimal _monthlyDeposit = 0m; - - /// - /// Initializes a new instance of the class with the specified owner name, initial balance, and optional monthly deposit amount. - /// - /// The name of the account owner or gift card recipient. - /// The initial amount loaded onto the gift card. - /// The optional amount to be automatically deposited each month. Defaults to 0 (no monthly deposits). - /// - /// This constructor creates a gift card account with an initial balance and an optional recurring monthly deposit. - /// The monthly deposit parameter allows for automatic top-ups, making this suitable for allowance accounts or - /// subscription-based gift cards. If monthlyDeposit is 0 or not specified, no automatic deposits will occur. - /// The account inherits standard banking functionality from with a minimum balance of $0. - /// - public GiftCardAccount(string name, decimal initialBalance, decimal monthlyDeposit = 0) : base(name, initialBalance) - => _monthlyDeposit = monthlyDeposit; - - /// - /// - /// For gift card accounts, month-end processing includes applying automatic monthly deposits when configured. - /// If a monthly deposit amount was specified during account creation and is greater than zero, the amount is - /// automatically deposited with the note "Add monthly deposit". This feature enables recurring funding scenarios - /// such as monthly allowances or subscription top-ups. If no monthly deposit was configured (_monthlyDeposit is 0), - /// no transactions are added during month-end processing. - /// - public override void PerformMonthEndTransactions() - { - if (_monthlyDeposit != 0) - { - MakeDeposit(_monthlyDeposit, DateTime.Now, "Add monthly deposit"); - } - } -} diff --git a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/InterestEarningAccount.cs b/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/InterestEarningAccount.cs deleted file mode 100644 index 15a9f77c52e29..0000000000000 --- a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/InterestEarningAccount.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace OOProgramming; - -/// -/// Represents an interest-earning bank account that extends with monthly interest payments. -/// Earns interest on balances above $500 at a rate of 2% annually, applied monthly. -/// -/// -/// An interest-earning account is a specialized savings account that rewards customers for maintaining higher balances. -/// Interest is only earned when the account balance exceeds $500, encouraging customers to maintain substantial deposits. -/// The annual interest rate of 2% is applied monthly to qualifying balances, providing a simple savings incentive. -/// This account type uses the standard minimum balance of $0 from the base class. -/// -public class InterestEarningAccount : BankAccount -{ - /// - /// Initializes a new instance of the class with the specified owner name and initial balance. - /// - /// The name of the account owner. - /// The initial deposit amount for the account. - /// - /// This constructor calls the base constructor with a default minimum balance of $0. - /// Interest earnings will begin in the first month-end processing cycle if the balance exceeds $500. - /// The account uses the same transaction tracking and balance calculation mechanisms as the base account type. - /// - public InterestEarningAccount(string name, decimal initialBalance) : base(name, initialBalance) - { - } - - /// - /// - /// For interest-earning accounts, month-end processing includes calculating and applying interest payments on qualifying balances. - /// Interest is only earned when the account balance exceeds $500. The interest calculation uses an annual rate of 2% (0.02) - /// applied to the full balance. The interest payment is deposited as a regular transaction with the note "apply monthly interest". - /// If the balance is $500 or below, no interest is earned and no transactions are added during month-end processing. - /// - public override void PerformMonthEndTransactions() - { - if (Balance > 500m) - { - decimal interest = Balance * 0.02m; - MakeDeposit(interest, DateTime.Now, "apply monthly interest"); - } - } -} diff --git a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/LineOfCreditAccount.cs b/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/LineOfCreditAccount.cs deleted file mode 100644 index 3e6dac527be6e..0000000000000 --- a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/LineOfCreditAccount.cs +++ /dev/null @@ -1,57 +0,0 @@ -namespace OOProgramming; - -/// -/// Represents a line of credit account that extends with credit limit functionality. -/// Allows negative balances up to a specified credit limit and applies monthly interest charges on outstanding balances. -/// -/// -/// A line of credit account differs from a regular bank account in that it allows the balance to go negative -/// up to a predefined credit limit. When the balance is negative (indicating borrowed money), the account -/// accrues monthly interest charges at a rate of 7% annually. Overdraft fees of $20 are applied when -/// withdrawals exceed the available credit limit. -/// -class LineOfCreditAccount : BankAccount -{ - /// - /// Initializes a new instance of the class with the specified owner name, initial balance, and credit limit. - /// - /// The name of the account owner. - /// The initial deposit amount for the account. - /// The maximum credit limit available for borrowing. This value should be positive and represents the maximum negative balance allowed. - /// - /// The constructor converts the credit limit to a negative minimum balance by passing -creditLimit to the base constructor. - /// This allows the account to have a negative balance up to the specified credit limit. For example, a credit limit of $1000 - /// means the account can have a balance as low as -$1000. - /// - public LineOfCreditAccount(string name, decimal initialBalance, decimal creditLimit) : base(name, initialBalance, -creditLimit) - { - } - - /// - /// - /// For line of credit accounts, month-end processing includes calculating and applying interest charges on negative balances. - /// Interest is calculated at an annual rate of 7% (0.07) applied monthly to the outstanding balance. The interest charge - /// is applied as a withdrawal transaction with the note "Charge monthly interest". If the balance is positive or zero, - /// no interest charges are applied. - /// - public override void PerformMonthEndTransactions() - { - if (Balance < 0) - { - // Negate the balance to get a positive interest charge: - decimal interest = -Balance * 0.07m; - MakeWithdrawal(interest, DateTime.Now, "Charge monthly interest"); - } - } - - /// - /// - /// Line of credit accounts handle overdrafts by applying a fixed $20 overdraft fee when withdrawals exceed the available - /// credit limit. Unlike the base implementation which throws an exception, this method returns a fee transaction that - /// gets added to the account. This allows the withdrawal to proceed while documenting the penalty for exceeding the limit. - /// - protected override Transaction? CheckWithdrawalLimit(bool isOverdrawn) => - isOverdrawn - ? new Transaction(-20, DateTime.Now, "Apply overdraft fee") - : default; -} diff --git a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/Program.cs b/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/Program.cs deleted file mode 100644 index 6ecc812eedbcb..0000000000000 --- a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/Program.cs +++ /dev/null @@ -1,65 +0,0 @@ -using OOProgramming; - -IntroToClasses(); - -// -var giftCard = new GiftCardAccount("gift card", 100, 50); -giftCard.MakeWithdrawal(20, DateTime.Now, "get expensive coffee"); -giftCard.MakeWithdrawal(50, DateTime.Now, "buy groceries"); -giftCard.PerformMonthEndTransactions(); -// can make additional deposits: -giftCard.MakeDeposit(27.50m, DateTime.Now, "add some additional spending money"); -Console.WriteLine(giftCard.GetAccountHistory()); - -var savings = new InterestEarningAccount("savings account", 10000); -savings.MakeDeposit(750, DateTime.Now, "save some money"); -savings.MakeDeposit(1250, DateTime.Now, "Add more savings"); -savings.MakeWithdrawal(250, DateTime.Now, "Needed to pay monthly bills"); -savings.PerformMonthEndTransactions(); -Console.WriteLine(savings.GetAccountHistory()); -// - -// -var lineOfCredit = new LineOfCreditAccount("line of credit", 0, 2000); -// How much is too much to borrow? -lineOfCredit.MakeWithdrawal(1000m, DateTime.Now, "Take out monthly advance"); -lineOfCredit.MakeDeposit(50m, DateTime.Now, "Pay back small amount"); -lineOfCredit.MakeWithdrawal(5000m, DateTime.Now, "Emergency funds for repairs"); -lineOfCredit.MakeDeposit(150m, DateTime.Now, "Partial restoration on repairs"); -lineOfCredit.PerformMonthEndTransactions(); -Console.WriteLine(lineOfCredit.GetAccountHistory()); -// -static void IntroToClasses() -{ - var account = new BankAccount("", 1000); - Console.WriteLine($"Account {account.Number} was created for {account.Owner} with {account.Balance} balance."); - - account.MakeWithdrawal(500, DateTime.Now, "Rent payment"); - Console.WriteLine(account.Balance); - account.MakeDeposit(100, DateTime.Now, "friend paid me back"); - Console.WriteLine(account.Balance); - - Console.WriteLine(account.GetAccountHistory()); - - // Test that the initial balances must be positive: - try - { - var invalidAccount = new BankAccount("invalid", -55); - } - catch (ArgumentOutOfRangeException e) - { - Console.WriteLine("Exception caught creating account with negative balance"); - Console.WriteLine(e.ToString()); - } - - // Test for a negative balance - try - { - account.MakeWithdrawal(750, DateTime.Now, "Attempt to overdraw"); - } - catch (InvalidOperationException e) - { - Console.WriteLine("Exception caught trying to overdraw"); - Console.WriteLine(e.ToString()); - } -} diff --git a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/object-oriented-programming.csproj b/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/object-oriented-programming.csproj deleted file mode 100644 index b8b9658ca3968..0000000000000 --- a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/object-oriented-programming.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - Exe - net10.0 - OOProgramming - oo-programming - enable - enable - True - - - diff --git a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/transaction.cs b/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/transaction.cs deleted file mode 100644 index 38dc60ba7889c..0000000000000 --- a/docs/csharp/fundamentals/tutorials/snippets/xml-documentation/transaction.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace OOProgramming; - -/// -/// Represents an immutable financial transaction with an amount, date, and descriptive notes. -/// -/// The transaction amount. Positive values represent credits/deposits, negative values represent debits/withdrawals. -/// The date and time when the transaction occurred. -/// Descriptive notes or memo text associated with the transaction. -public record Transaction(decimal Amount, DateTime Date, string Notes);