To write a C# program using interface concept.
Create an interface.
Create a child class.
Declare 2 functions deposit() and withdrawal() as abstract methods in the interface.
Create those 2 functions in the child class and perform respective operation.
Use while loop and and switch case to Get the choice from the user whether to perform withdrawal or deposit operation.
After performing the functions display the remaining balance of the use.
using System;
public interface Bank
{
void deposit();
void withdrawal();
}
class Program : Bank
{
int amount, ch, balance = 5000;
public Program()
{
Console.WriteLine("1.Deposit\n2.Withdrawal");
ch = Convert.ToInt32(Console.ReadLine());
if (ch == 1)
{
deposit();
}
else
{
withdrawal();
}
}
public void withdrawal()
{
int amount = Convert.ToInt32(Console.ReadLine());
balance -= amount;
Console.WriteLine(balance);
}
public void deposit()
{
int amount = Convert.ToInt32(Console.ReadLine());
balance += amount;
Console.WriteLine(balance);
}
}
class example
{
public static void Main()
{
Program c = new Program();
c.deposit();
c.withdrawal();
}
}
![279613066-e8957b3d-d1fb-48c4-a2d1-76bd09f922ad](https://private-user-images.githubusercontent.com/94165322/281135885-6c276da2-f71f-4405-891f-65c9f0add589.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUyOTY4MTAsIm5iZiI6MTcyNTI5NjUxMCwicGF0aCI6Ii85NDE2NTMyMi8yODExMzU4ODUtNmMyNzZkYTItZjcxZi00NDA1LTg5MWYtNjVjOWYwYWRkNTg5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTAyVDE3MDE1MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQwN2JlNDE4MjQxOGQzMTg1ZDVhNDk5MzhhMzRjYTIzODBhZTIzNTY3M2NjMmFhY2NmNGY5YjVhMTEyYTlhNTQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.GOgOBw0O6UtU6v7mk2KY7RS3_dRee3TlHn7d48WFBdY)
Thus the C# program using interface concept has been implemented successfully.