Q2. 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 BankAccountLibrary
{
public class ICICI: BankAccount // Inherit this from BankAccount
{
private double annualInterestRate = 7.0;
public ICICI(double amount)
: base(amount)
{
}
public override bool Withdraw(double amount)
{
// If Balance – amount is >= 0 then only WithDraw is possible.
// Write the code to achieve the same.
if (balance - amount >= 0){
balance -= amount;
Console.WriteLine("The amount has been withdrawed.");
return true;
}
return false;
}
public override bool Transfer(IBankAccount toAccount, double amount)
{
// If Balance – Withdraw is >= 1000 then only transfer can take place.
// Write the code to achieve the same.
if (balance - amount >= 1000)
{
return (this.Deposit(amount) && toAccount.Withdraw(amount));
}
return false;
}
public void CalculateInterest()
{
if (AccountType == BankAccountTypeEnum.Saving)
{
double savingsBalance = balance;
savingsBalance *= (1 + (annualInterestRate / 100 / 12));
Console.WriteLine("Balance for HSBC account: {0}", savingsBalance.ToString("C"));
}
else {
Console.WriteLine("Balance for HSBC account: 0.0");
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankAccountLibrary
{
public class HSBC : BankAccount // Inherit this from BankAccount
{
private double annualInterestRate = 5.0;
public HSBC(double amount)
: base(amount)
{
}
public override bool Withdraw(double amount)
{
// If Balance – amount is >= 5000 then only WithDraw is possible.
// Write the code to achieve the same.
if (balance - amount >= 5000)
{
balance -= amount;
Console.WriteLine("The amount has been withdrawed.");
return true;
}
return false;
}
public override bool Transfer(IBankAccount toAccount, double amount)
{
// If Balance – Withdraw is >= 5000 then only transfer can take place.
// Write the code to achieve the same.
if (balance - amount >= 5000)
{
return (this.Deposit(amount) && toAccount.Withdraw(amount));
}
return false;
}
public void CalculateInterest()
{
if (AccountType == BankAccountTypeEnum.Saving)
{
double savingsBalance = balance;
savingsBalance *= (1 + (annualInterestRate / 100 / 12));
Console.WriteLine("Balance for HSBC account: {0}", savingsBalance.ToString("C"));
}
else
{
Console.WriteLine("Balance for HSBC account: 0.0");
}
}
}
}
Comments
Leave a comment