JaromeMercado / IT1205

0 stars 0 forks source link

IT2105_LabActivity5_MERCADO #1

Open JaromeMercado opened 2 weeks ago

JaromeMercado commented 2 weeks ago

using System;

class BankAccount { private decimal balance;

public BankAccount()
{
    balance = 0.0m; 
}

public void Deposit(decimal amount)
{
    if (amount > 0)
    {
        balance += amount;
        Console.WriteLine($"${amount} has been deposited to your account.");
    }
}

public void Withdraw(decimal amount)
{
    if (amount > 0 && amount <= balance)
    {
        balance -= amount;
        Console.WriteLine($"${amount} has been withdrawn from your account.");
    }
}

public void CheckBalance()
{
    Console.WriteLine($"Your current balance is: ${balance}");
}

}

class Program { static void Main(string[] args) { BankAccount account = new BankAccount(); int choice;

    do
    {
        Console.WriteLine("\nBank Account Menu:");
        Console.WriteLine("1. Deposit");
        Console.WriteLine("2. Withdraw");
        Console.WriteLine("3. Check Balance");
        Console.WriteLine("4. Exit");
        Console.Write("Choose an option (1-4): ");
        choice = Convert.ToInt32(Console.ReadLine());

        switch (choice)
        {
            case 1:
                Console.Write("Enter the amount to deposit: ");
                decimal depositAmount = Convert.ToDecimal(Console.ReadLine());
                account.Deposit(depositAmount);
                break;

            case 2:
                Console.Write("Enter the amount to withdraw: ");
                decimal withdrawAmount = Convert.ToDecimal(Console.ReadLine());
                account.Withdraw(withdrawAmount);
                break;

            case 3:
                account.CheckBalance();
                break;

            case 4:
                Console.WriteLine("Exiting the program. Thank you!");
                break;
        }
    } while (choice != 4);
}
JaromeMercado commented 2 weeks ago

image