Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using System; namespace BankAccaount { class Program { static void Main(string[]

ID: 3641494 • Letter: U

Question

using System;
namespace BankAccaount
{
class Program
{
static void Main(string[] args)
{
//Create the array of Acount
Account[] MyAccount = new Account[2];
//Initialize the saving account
MyAccount[0] = new SavingAccount(1000m, 4m);
//Initialize the checking account
MyAccount[1] = new CheckingAccount(2000.00m, 0.5m);
Console.WriteLine("Welcome! ============ MY Bank");
Console.WriteLine("");
//Display the current balance of each account
Console.WriteLine("Your SavingAcount Current Balance : $" + MyAccount[0].Balance.ToString());
Console.WriteLine("Your CheckingAcount Current Balance : $" + MyAccount[1].Balance.ToString());
Console.WriteLine("");
//An operation of account
ProcessAccount(MyAccount);
//Select another operation
string s;
do
{
do
{
Console.WriteLine("Do you need another operation? (Y = Yes ; N = No)");
s = Console.ReadLine();
} while (s.ToUpper() != "Y" && s.ToUpper() != "N");
if (s.ToUpper() == "Y")
ProcessAccount(MyAccount);
} while (s.ToUpper() == "Y");
Console.WriteLine("");
Console.WriteLine("Thank You! ============ MY Bank");
Console.ReadLine();
}
//Extract Method: An operation of account
private static void ProcessAccount(Account[] MyAccount)
{
string s;
do
{
Console.WriteLine("Please Select Deposit Or Withdraw……");
Console.WriteLine("1. Deposit 2. Withdraw");
s = Console.ReadLine();
}
while (s != "1" && s != "2");
string s_amount;
do
{
Console.WriteLine("Please Input Amount…..(Integer Requested)");
s_amount = Console.ReadLine();
}
while (!Regex.IsMatch(s_amount, "^[0-9]*[1-9][0-9]*$"));
decimal amount = decimal.Parse(s_amount);
switch (s)
{
case "1":
do
{
Console.WriteLine("Please Select Deposit Acount……");
Console.WriteLine("1. Saving 2. Checking");
s = Console.ReadLine();
} while (s != "1" && s != "2");
switch (s)
{
case "1":
MyAccount[0].Credit(amount);
break;
case "2":
MyAccount[1].Credit(amount);
break;
}
break;
case "2":
do
{
Console.WriteLine("Please Select Withdraw Acount……");
Console.WriteLine("1. Saving 2. Checking");
s = Console.ReadLine();
} while (s != "1" && s != "2");
switch (s)
{
case "1":
MyAccount[0].Debit(amount);
break;
case "2":
MyAccount[1].Debit(amount);
break;
}
break;
}
Console.WriteLine("");
Console.WriteLine("Your SavingAcount Final Balance : $" + MyAccount[0].Balance.ToString());
Console.WriteLine("Your ChechingAcount Final Balance : $" + MyAccount[1].Balance.ToString());
Console.WriteLine("");
}
}
//Base Class of account
class Account
{
decimal balance;
public Account() { Balance = 0.0m; }
public Account(decimal amount)
{
Balance = amount;
}
public decimal Balance
{
get { return balance; }
set
{
if (value >= 0)
balance = value;
else
{
balance = 0.0m;
Console.WriteLine("Wrong amount!Please check it.");
}
}
}
public virtual void Credit(decimal amount)
{
Balance += amount;
}
public virtual bool Debit(decimal amount)
{
if (Balance >= amount)
{
Balance -= amount;
return true;
}
else
{
Console.WriteLine("Sorry! Debit amount exceeded acount balance!");
return false;
}
}
}
//the class of saving account
class SavingAccount : Account
{
private decimal interestrate;
public SavingAccount() { interestrate = 0.0m; }
public SavingAccount(decimal amount, decimal rate)
: base(amount)
{
interestrate = rate;
//calculate interest when the saving account is created first time
decimal interest = CalculateInterest();
Credit(interest);
}
public decimal CalculateInterest()
{
decimal interest = base.Balance * interestrate * 0.01m;
return interest;
}
}
//the class of checking account
class CheckingAccount : Account
{
decimal transactionfee;
public CheckingAccount() { transactionfee = 0.0m; }
public CheckingAccount(decimal amount, decimal fee)
: base(amount)
{
transactionfee = fee;
}
override public void Credit(decimal amount)
{
base.Credit(amount - transactionfee);
}
override public bool Debit(decimal amount)
{
return base.Debit(amount + transactionfee);
}
}
}

Explanation / Answer

what is your problem?

The above code only misses 'using System.Text.RegularExpressions;' in its header...

using System;
using System.Text.RegularExpressions; //for Regex