Let’s build a sample banking program to perform the common tasks like Withdraw and Deposit.
class Bank
{
public decimal BankAccount { get; set; }
public Bank(decimal bankAccount)
{
BankAccount = bankAccount;
}
public void Withdraw(decimal amount)
{
BankAccount -= amount;
Console.WriteLine($"Withdrawn from your account: {amount}.Amount in your account: {BankAccount}");
}
public void Deposit(decimal amount)
{
BankAccount += amount;
Console.WriteLine($"Credited to your account: {amount}.Amount in your account: {BankAccount}");
}
}
static void Main()
{
Console.Write("Enter the initial amount in your bank account:");
Bank bank = new Bank(decimal.Parse(Console.ReadLine()));
Console.Write("Enter how much money you want to withdraw from your bank account:");
bank.Withdraw(decimal.Parse(Console.ReadLine()));
Console.Write("Enter how much you want to credit to your bank account:");
bank.Deposit(decimal.Parse(Console.ReadLine()));
Console.ReadKey();
}
Comments
Leave a comment