0% found this document useful (0 votes)
4 views3 pages

c11 - Lab Task One

The document contains a C# implementation of a banking system with an abstract class 'BankAccount' and a derived class 'SavingsAccount'. The 'BankAccount' class provides methods for setting account details, depositing, withdrawing, and checking the balance, while 'SavingsAccount' adds functionality for interest calculation. The 'Main' method demonstrates the creation and usage of a 'SavingsAccount' instance.

Uploaded by

Sarathi M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

c11 - Lab Task One

The document contains a C# implementation of a banking system with an abstract class 'BankAccount' and a derived class 'SavingsAccount'. The 'BankAccount' class provides methods for setting account details, depositing, withdrawing, and checking the balance, while 'SavingsAccount' adds functionality for interest calculation. The 'Main' method demonstrates the creation and usage of a 'SavingsAccount' instance.

Uploaded by

Sarathi M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1)

Code:

using System;

public abstract class BankAccount


{
public string AccountNumber;
public string AccountHolder;
protected double Balance;

public void SetValue(string accNumber, string accHolder)


{
AccountNumber = accNumber;
AccountHolder = accHolder;
Balance = 0;
}

public void Deposit(double amt)


{
if (amt > 0)
{
Balance += amt;
Console.WriteLine("Deposited: " + amt);
}
else
{
Console.WriteLine("Invalid Deposit Amount");
}
}

public virtual void Withdraw(double amt)


{
if (amt > 0 && amt <= Balance)
{
Balance -= amt;
Console.WriteLine("Withdrawn: " + amt);
}
else
{
Console.WriteLine("Invalid or Insufficient Balance");
}
}

public double GetBalance()


{
return Balance;
}

public abstract void DisplayAccountDetails();


}

public class SavingsAccount : BankAccount


{
private double interestRate;

public SavingsAccount(string accNumber, string accHolder, double


interest)
{
SetValue(accNumber, accHolder);
interestRate = interest;
}

public void AddInterest()


{
double interest = Balance * interestRate / 100;
Balance += interest;
Console.WriteLine("Interest Added: " + interest);
}

public override void DisplayAccountDetails()


{
Console.WriteLine("Savings Account Details");
Console.WriteLine("-----------------------");
Console.WriteLine("Account Number: " + AccountNumber);
Console.WriteLine("Account Holder: " + AccountHolder);
Console.WriteLine("Balance: " + Balance);
Console.WriteLine("Interest Rate: " + interestRate + "%");
}
}

class Program
{
static void Main()
{
SavingsAccount sa = new SavingsAccount("SA100", "Tharani", 5.0);
sa.Deposit(1000);
sa.AddInterest();
sa.Withdraw(200);
sa.DisplayAccountDetails();
}
}
Output:

You might also like