Task 5: Implement only the Deposit method to increment the Balance. Keep the other two methods abstractin the class.
Task 6: Now let’s create concrete classes which are inherited from the BankAccount class.
Concrete Bank Account Classes having their own rules for Minimum Balance class ICICI // Inherit this from BankAccount
{
Withdraw() // Override this method
{
// If Balance – amount is >= 0 then only WithDraw is possible.
// Write the code to achieve the same.
}
Transfer() //Override this method
{
// If Balance – Withdraw is >= 1000 then only transfer can take place.
// Write the code to achieve the same.
}
}
class HSBC // Inherit this from BankAccount
{
Withdraw() //Override this method
{
// If Balance – amount is >= 5000 then only WithDraw is possible.
// Write the code to achieve the same.
}
Transfer() //Override this method
{
// If Balance – Withdraw is >= 5000 then only transfer can
take place.
// Write the code to achieve the same.
}
}
Task 5:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankAccountLibrary
{
class ICICI: BankAccount // Inherit this from BankAccount
{
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;
}
}
}
Task 6:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BankAccountLibrary
{
class HSBC : BankAccount // Inherit this from BankAccount
{
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;
}
}
}
Comments
Leave a comment