namespace Interface
{
interface IBankAccount
{
bool Deposit(decimal amount);
bool Withdraw(decimal amount);
decimal Balance { get; }
}
class Program
{
static void Main(string[] args)
{
// Declare an interface instance
IBankAccount savingAccount = new SavingAccount();
Console.WriteLine("Saving Account");
savingAccount.Deposit(200);
savingAccount.Withdraw(300);
savingAccount.ToString();
IBankAccount currentAccount = new CurrentAccount();
Console.WriteLine("Current Account");
currentAccount.Deposit(500);
currentAccount.Withdraw(200);
currentAccount.ToString();
Console.ReadLine();
}
}
public class SavingAccount : IBankAccount
{
private decimal _balance;
private decimal _perDayLimit;
public bool Deposit(decimal amount)
{
_balance += amount;
return true;
}
public bool Withdraw(decimal amount)
{
if (_balance < amount)
{
Console.WriteLine("Insufficient balance!");
return false;
}
else if (_perDayLimit + amount > 5000) //limit is 5000
{
Console.WriteLine("Withdrawal attempt failed!");
return false;
}
else
{
_balance -= amount;
_perDayLimit += amount;
Console.WriteLine(String.Format("Successfully withdraw: {0,6:C}", amount));
return true;
}
}
public decimal Balance
{
get { return _balance; }
}
public override string ToString()
{
return String.Format("Saving Account Balance = {0,6:C}", _balance);
}
}
public class CurrentAccount : IBankAccount
{
private decimal _balance;
public bool Deposit(decimal amount)
{
_balance += amount;
return true;
}
public bool Withdraw(decimal amount)
{
if (_balance < amount)
{
Console.WriteLine("Insufficient balance!");
return false;
}
else
{
_balance -= amount;
Console.WriteLine(String.Format("Successfully withdraw: {0,6:C}", amount));
return true;
}
}
public decimal Balance
{
get { return _balance; }
}
public override string ToString()
{
return String.Format("Current Account Balance = {0,6:C}", _balance);
}
}
}
{
interface IBankAccount
{
bool Deposit(decimal amount);
bool Withdraw(decimal amount);
decimal Balance { get; }
}
class Program
{
static void Main(string[] args)
{
// Declare an interface instance
IBankAccount savingAccount = new SavingAccount();
Console.WriteLine("Saving Account");
savingAccount.Deposit(200);
savingAccount.Withdraw(300);
savingAccount.ToString();
IBankAccount currentAccount = new CurrentAccount();
Console.WriteLine("Current Account");
currentAccount.Deposit(500);
currentAccount.Withdraw(200);
currentAccount.ToString();
Console.ReadLine();
}
}
public class SavingAccount : IBankAccount
{
private decimal _balance;
private decimal _perDayLimit;
public bool Deposit(decimal amount)
{
_balance += amount;
return true;
}
public bool Withdraw(decimal amount)
{
if (_balance < amount)
{
Console.WriteLine("Insufficient balance!");
return false;
}
else if (_perDayLimit + amount > 5000) //limit is 5000
{
Console.WriteLine("Withdrawal attempt failed!");
return false;
}
else
{
_balance -= amount;
_perDayLimit += amount;
Console.WriteLine(String.Format("Successfully withdraw: {0,6:C}", amount));
return true;
}
}
public decimal Balance
{
get { return _balance; }
}
public override string ToString()
{
return String.Format("Saving Account Balance = {0,6:C}", _balance);
}
}
public class CurrentAccount : IBankAccount
{
private decimal _balance;
public bool Deposit(decimal amount)
{
_balance += amount;
return true;
}
public bool Withdraw(decimal amount)
{
if (_balance < amount)
{
Console.WriteLine("Insufficient balance!");
return false;
}
else
{
_balance -= amount;
Console.WriteLine(String.Format("Successfully withdraw: {0,6:C}", amount));
return true;
}
}
public decimal Balance
{
get { return _balance; }
}
public override string ToString()
{
return String.Format("Current Account Balance = {0,6:C}", _balance);
}
}
}
No comments:
Post a Comment