0% found this document useful (0 votes)
1K views

Bank Operations Using C#

This document defines a BankAccount class with properties and methods for account name, number, balance, interest rate, deposit, withdrawal, and balance calculation after a certain number of months. It also defines a Program class with a Main method that uses a list of BankAccount objects to allow the user to set up accounts, check balances, make deposits, make withdrawals, and terminate the program. User input and output is handled through the console to perform these banking operations and manage the list of accounts.

Uploaded by

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

Bank Operations Using C#

This document defines a BankAccount class with properties and methods for account name, number, balance, interest rate, deposit, withdrawal, and balance calculation after a certain number of months. It also defines a Program class with a Main method that uses a list of BankAccount objects to allow the user to set up accounts, check balances, make deposits, make withdrawals, and terminate the program. User input and output is handled through the console to perform these banking operations and manage the list of accounts.

Uploaded by

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

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

class BankAccount
{
public string name;
int accountNum;
public double balance = 0;
double interest = 0;
public BankAccount(string namae, double firstDep)
{
name = namae;
balance += firstDep;
}

public void setIntRate(double per)


{
interest = per;
}

public double getBal()


{
return balance;
}

public string getName()


{
return this.name;
}

public void deposit(double addAmt)


{
balance += addAmt;
}

public bool withdraw(double outAmt)


{
bool chk = true;
if (outAmt <= balance)
{
balance -= outAmt;
}
else if (outAmt > balance)
{
chk = false;
}
return chk;
}

public double getBalAfter(int mos)


{
double prin = balance;
double intFeed;
for (int g = 1; g <= mos; g++)
{
intFeed = prin * interest;
prin += intFeed;
}
return prin;
}
}
class Program
{
static void Main(string[] args)
{
List<BankAccount> bank = new List<BankAccount>();
while (true)
{
Console.Write("1. Set up account\n2. Check balance\n3. Deposit\n4.
Withdraw\nX. Terminate\n\nSelect Function: ");
string selGo = Console.ReadLine().ToUpper();
Console.WriteLine("\n");
if (selGo == "1")
{
Console.Write("Enter name: ");
string name = Console.ReadLine();
Console.Write("Enter initial balance: ");
double init = double.Parse(Console.ReadLine());
bank.Add(new BankAccount(name, init));
Console.WriteLine("Bank Account Added!");
Console.ReadLine();
}
else if (selGo == "2")
{
Console.Write("Enter name: ");
string nmChk = Console.ReadLine();
for (int ix = 0; ix < bank.Count; ix++)
{
if (bank[ix].name == nmChk)
{
Console.WriteLine("Account Found!\nName: {0}\nBalance:
{1}", bank[ix].name, bank[ix].balance);
}
}
Console.ReadLine();
}
else if (selGo == "3")
{
Console.Write("Enter name: ");
string nmChk = Console.ReadLine(), nmNow = null;
int accNum = -1;
for (int ix = 0; ix < bank.Count; ix++)
{
if (bank[ix].name == nmChk)
{
nmNow = nmChk;
accNum = ix;
}
}
if (accNum != -1)
{
Console.Write("Amount to Deposit: ");
bank[accNum].deposit(double.Parse(Console.ReadLine()));
Console.WriteLine("Amount successfully deposited!");
}
else { Console.WriteLine("Account not found!"); }
Console.ReadLine();
}
else if (selGo == "4")
{
Console.Write("Enter name: ");
string nmChk = Console.ReadLine(), nmNow = null;
int accNum = -1;
for (int ix = 0; ix < bank.Count; ix++)
{
if (bank[ix].name == nmChk)
{
nmNow = nmChk;
accNum = ix;
}
}
if (accNum != -1)
{
Console.Write("Amount to Withdraw: ");
bool ok =
bank[accNum].withdraw(double.Parse(Console.ReadLine()));
if (ok)
{
Console.WriteLine("Amount successfully withdrawn!");
if (bank[accNum].balance == 0)
{
bank[accNum] = null;
Console.WriteLine("Account closed!");
}
}
else { Console.WriteLine("Insufficient funds!"); }
}
else { Console.WriteLine("Account not found!"); }
Console.ReadLine();
}

else if (selGo == "X")


{
break;
}
else
{
Console.WriteLine("Invalid Syntax!");
Console.ReadLine();
}
Console.Clear();
}
}
}

You might also like