There is a Change request from the customer. It is as follows: You need to calculate Interest paid by banks on Saving Account.
Task 1 : Add a function declaration “void CalculateInterest()” in the interface. Define the functions in the concrete classes such as ICICI accounts get 7% interest and HSBC gives 5% interest.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace C_SHARP
{
class Program
{
interface IInterest
{
void CalculateInterest();
}
class SavingsAccount
{
private double annualInterestRate = 0.0;
private double savingsBalance;
public SavingsAccount(double initBalance)
{
savingsBalance = initBalance;
}
public double getBalance() { return savingsBalance; }
public double getInterestRate()
{
return annualInterestRate;
}
}
class ICICI: SavingsAccount, IInterest
{
//concrete classes such as ICICI accounts get 7%
private double annualInterestRate = 7.0;
public ICICI(double initBalance):base(initBalance)
{
}
public void CalculateInterest()
{
double savingsBalance=getBalance();
savingsBalance *= (1 + (annualInterestRate / 100 / 12));
Console.WriteLine("Saving balance for ICICI account: {0}", savingsBalance.ToString("C"));
}
}
class HSBC : SavingsAccount, IInterest
{
//SBC gives 5% interest.
private double annualInterestRate = 5.0;
public HSBC(double initBalance)
: base(initBalance)
{
}
public void CalculateInterest()
{
double savingsBalance = getBalance();
savingsBalance *= (1 + (annualInterestRate / 100 / 12));
Console.WriteLine("Saving balance for HSBC account: {0}", savingsBalance.ToString("C"));
}
}
static void Main(string[] args)
{
IInterest savingsAccountICICI = new ICICI(5000);
savingsAccountICICI.CalculateInterest();
IInterest savingsAccountHSBC = new HSBC(5000);
savingsAccountHSBC.CalculateInterest();
Console.ReadKey();
}
}
}
Comments
Leave a comment