Wednesday, August 29, 2007

// program_id overrideInterface.cs
// description This program demonstrates a class
// derived from a class that overrides
// the base class' implementation
// of the interface's method.
//

using System;

namespace theChecking
{
interface IAccounts
{
decimal theBalance {set; get;}
void Deposit(decimal theAmount);

void Withdrawal(decimal theAmount);
}

interface IFee: IAccounts
{
decimal theFee {get; set;}
void CalculateFee();
}

class Checking: IFee
{
private decimal Fee;
public decimal theFee
{
get
{
return Fee;
}
set
{

Fee = value;
}
}

private decimal Balance;
public decimal theBalance
{
get
{
return Balance;
}
set
{
Balance = value;
}
}
public Checking()
{
Balance = 0.00M;
}
public void Deposit(decimal theAmount)
{
Balance += theAmount;
}
public void Withdrawal(decimal theAmount)
{
Balance -= theAmount;
}
public virtual void CalculateFee()
{
Balance -= Fee;
}
}
class Savings : Checking
{
public override void CalculateFee()
{
theBalance *= (1 + theFee);
}
public decimal ShowInterest()
{
return (theBalance * theFee);
}

}
class theProgram
{
static void Main()
{

Checking checkingAccount = new Checking();

Savings savingsAccount = new Savings();

Console.Clear();

Console.Write("What is the checking account fee? ");
checkingAccount.theFee = Decimal.Parse(Console.ReadLine());

Console.Write("\nWhat was the checking account deposits? ");
checkingAccount.Deposit(Decimal.Parse(Console.ReadLine()));

Console.Write("What was the checking account withdrawals? ");
checkingAccount.Withdrawal(Decimal.Parse(Console.ReadLine()));


if(checkingAccount.theBalance <= 500.00m)
{
checkingAccount.CalculateFee();
Console.WriteLine("\nThe checking account was charged a fee of {0:c}",
checkingAccount.theFee);
}

Console.WriteLine("\nCurrent balance of the checking account is {0:c}.",
checkingAccount.theBalance);

Console.Write("\n\nWhat is the savings account interest rate? ");
savingsAccount.theFee = Decimal.Parse(Console.ReadLine())/100;

Console.Write("\nWhat was the savings account deposits? ");
savingsAccount.Deposit(Decimal.Parse(Console.ReadLine()));

Console.Write("What was the savings account withdrawals? ");
savingsAccount.Withdrawal(Decimal.Parse(Console.ReadLine()));

if(savingsAccount.theBalance >= 500.00m)

{
Console.WriteLine("\nThe savings account was awarded an interest fee of {0:c}",
savingsAccount.ShowInterest());
savingsAccount.CalculateFee();
}
Console.WriteLine("\nCurrent balance of the savings account is {0:c}.",
savingsAccount.theBalance);

Console.WriteLine("\n\n");
Console.ReadKey();
}

}
}

No comments: