Bank GUI Create a C# forms program for a banking application. Your program will
ID: 3725562 • Letter: B
Question
Bank GUI Create a C# forms program for a banking application. Your program will include an array of Account objects. The Account class should specify An integer accountiD instance variable .A decimal balance instance variable Properties to get and set those instance variables A withdraw method which deducts an amount from the balance .A deposit method which adds an amount to the balance The following program behavior is required When the Create Account Button is clicked, the program creates an account with an initial balance from the Amount text box. It ignores whatever is in the Account ID text box and displays a new Account ID in that box 1. 2. When the Execute Button is clicked, the program adjusts the balance for the account specified in the Account ID text box by the amount in the Amount text box. The deposit and withdraw buttons determine whether the amount is added or subtracted. If the Balance button is selected, the balance for the specified account is displayed. The program must support 19 simultaneous accounts with account IDs of 1-19 A report for all transactions must be displayed in the area below the buttons. The transaction report must be in a different color 3. 4. 5. Bank ITSE 2453 Bank Dalas, Teoas Bank ITSE 2453 Bank Dalas, Teas ITSE 2453 Bank Dallas, Texas 650 23 830 Deposit O Withdravw O Balance O Deposit O Balance Balance Create Account Create Account Account 12 Opened with a balance of $330Explanation / Answer
public static class Bank
{
public static List<Account1> AccountList = new List<Account1>();
private static int account_id = 100;
public static int acc_id
{
get { return account_id; }
set { account_id = value; }
}
public static void CreateAccount(string name,string pass, int amount)
{
Account1 a = new Account1(account_id, name,pass,amount);
account_id++;
AccountList.Add(a);
}
public static Account1 GetAccount(int id)
{
return (from a in AccountList
where a.Account_ID == id
select a).FirstOrDefault();
}
public static bool DeleteAccount(int id,string pass)
{
var accountToDelete = (from a in AccountList where a.Account_ID == id && a.Pass == pass select a).FirstOrDefault();
return AccountList.Remove(accountToDelete);
}
public static Account1 AddM(int id, int amount)
{
var addM = (from a in AccountList where a.Account_ID == id select a).FirstOrDefault();
addM.Amount += amount;
return addM;
}
public static Account1 TakeM(int id, int amount,string pass)
{
var takeM = (from a in AccountList where a.Account_ID == id && a.Pass==pass select a).FirstOrDefault();
takeM.Amount -= amount;
if (takeM.Amount <= 500)
{
takeM.Amount += amount;
MessageBox.Show("Sorry Rs.500 is the minimum Balance");
}
else
{
MessageBox.Show("WithDrawn Successfully");
}
return takeM;
}
public static void TranM(int id1, int id2, int amount,string pass)
{
var tranM1 = (from a in AccountList where a.Account_ID == id1 && a.Pass == pass select a).FirstOrDefault();
var tranM2 = (from a in AccountList where a.Account_ID == id2 select a).FirstOrDefault();
tranM1.Amount -= amount;
if (tranM1.Amount < 500)
{
tranM1.Amount += amount;
MessageBox.Show("Sorry Rs.500 is the minimum Balance");
}
else
{
tranM2.Amount += amount;
MessageBox.Show("Transfered Successfully!!");
}
}
}
public class Account1
{
public int Account_ID { get; set; }
public string Name { get; set; }
public int Amount { get; set; }
public string Pass { get; set; }
public Account1(int id, string name, string pass, int amount)
{
Account_ID = id;
Name = name;
Amount = amount;
Pass = pass;
}
ANOTHER METHOD
using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;
namespace Bank
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int _nextIndex = 0;
private Account[] _accounts = new Account[19];
private void createButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(accountIdTextBox.Text)) return;
var account = new Account();
int accountID;
int balance=0;
bool success=int.TryParse(accountIdTextBox.Text,out accountID);
int.TryParse(amountTextBox.Text, out balance);
if(success)
{
account.AccountId = accountID;
account.Balance = balance;
_accounts[_nextIndex] = account;
_nextIndex++;
}
resultLabel.Text = "Created Account: " + accountID + " with Balance " + balance;
}
private Account GetAccount(int id)
{
return _accounts.Where(x => x.AccountId == id).FirstOrDefault();
}
private void depositButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(accountIdTextBox.Text)) return;
int amount = 0;
int accountID;
bool success1 = int.TryParse(accountIdTextBox.Text, out accountID);
bool success2 = int.TryParse(amountTextBox.Text, out amount);
if(success1 && success2 && amount >0)
{
var selectedAccount = GetAccount(accountID);
selectedAccount.Balance += amount;
resultLabel.Text = "Account: " + accountID + " balance get deposit for " + amount;
}
}
private void withdrawButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(accountIdTextBox.Text)) return;
int amount = 0;
int accountID;
bool success1 = int.TryParse(accountIdTextBox.Text, out accountID);
bool success2 = int.TryParse(amountTextBox.Text, out amount);
if (success1 && success2 && amount > 0)
{
var selectedAccount = GetAccount(accountID);
selectedAccount.Balance -= amount;
resultLabel.Text = "Account: " + accountID + " balance withdrawed by " + amount;
}
}
private void ballanceButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(accountIdTextBox.Text)) return;
int amount = 0;
int accountID;
bool success1 = int.TryParse(accountIdTextBox.Text, out accountID);
if (success1)
{
var selectedAccount = GetAccount(accountID);
resultLabel.Text = "Account: " + accountID + ", Balance: " + selectedAccount.Balance;
}
}
}
ANOTHER METHOD
a class Account. An account has
a balance,
functions to add
and withdraw money,
and a function to inquire the current balance.
Pass a value into a constructor to set an initial balance.
If no value is passed the initial balance should be set to $0.
Charge a $5 penalty if an attempt is made to withdraw more money than available in the account.
Enhance the Account class to compute interest on the current balance.
class Account {
double balance;
double add(double sum) {
balance += sum;
return sum;
}
double withdraw(double sum) {
if (sum > balance) {
balance -= 5;
return -5; // this will come in handy in Prob. 6
} else {
balance -= sum;
return balance; // Notice: always >= 0 (never < 0)
}
}
double inquire() { return balance; }
Account() { balance = 0; }
Account(double sum) { balance = sum; }
double interest (double rate) {
return rate * balance;
}
}
a class Bank. This bank has two objects
checking
and savings
of the type Account that was developed in the preceding exercise.
Implement four instance methods:
deposit(double amount, String account)
withdraw(double amount, String account)
transfer(double amount, String account)
printBalances()
Here the account string is "S" or "C". For the deposit or withdrawal, it indicates which account is affected. For a transfer it indicates the account from which the money is taken; the money is automatically transferred to the other account.
class Bank {
Account checking;
Account savings;
void deposit(double amount, String account) {
if (account.equals("C")) checking.add(amount);
else // my default
savings.add(amount);
}
void withdraw(double amount, String account) {
if (account.equals("C")) checking.withdraw(amount);
else // my default
savings.withdraw(amount);
}
void transfer (double amount, String account) {
if (account.equals("C"))
if (checking.withdraw(amount) >= 0)
savings.add(amount);
else checking.add(5); // somewhat fault-tolerant
else // default
if (savings.withdraw(amount) >= 0)
checking.add(amount);
else savings.add(5); // no penalty for transfers
}
void printBalances() {
System.out.println(
"Checking: " + checking.inquire() +
" Savings: " + savings.inquire()
);
}
}
ONE MORE METHOD
#include<iostream.h>
#include<string.h>
#include<process.h>
class details
{
public:
char *name;
int age;
char branch[50];
char city[40];
void getdetails()
{
name=new char[20];
cout<<endl<<endl<<"**********Customer Details*********** "<<endl;
cout<<" -------- ------- "<<endl;
cout<<"Enter Name: ";
cin>>name;
cout<<"Enter Age: ";
cin>>age;
cout<<"Enter Branch: ";
cin>>branch;
cout<<"Enter City: ";
cin>>city;
cout<<"______________________________________"<<endl<<endl;
}
};
class bank
{
public:
static int accnumber;
long balance;
details d;
void getdata();
bank transfermoney(bank);
void deposit();
void withdrawal();
void newaccount();
void viewaccdetails();
};
int bank::accno=0;
void main()
{
char ch;
static int i=0;
bank *a[10];
int x,amt,k,j;
clrscr();
do
{
cout<<endl<<endl<<"************MENU************"<<endl;
cout<<" ---- "<<endl;
cout<<"1.Create new account 2.Deposit 3.Withdraw 4.Transfer credits 5.View account details ";
cout<<"Enter choice no.: ";
cin>>x;
switch(x)
{
case 1:
{
i++;
a[i]=new bank;
a[i]->newaccount();
break;
}
case 2:
{
cout<<"Enter account no.: ";
cin>>k;
a[k]->deposit();
break;
}
case 3:
{
cout<<"Enter account no.: ";
cin>>k;
a[k]->withdrawal();
break;
}
case 4:
{
cout<<"Enter the source and destination account nos.: ";
cin>>k>>j;
*a[j]=a[k]->transfermoney(*a[j]);
break;
}
case 5:
{
cout<<"Enter account no.: ";
cin>>k;
a[k]->viewaccdetails();
break;
}
}cout<<" Do you wish to continue[Press 'Y' to continue or 'N' to exit menu]: ";
cin>>ch;
}while(ch=='y'||ch=='Y');
}
bank bank::transfermoney(bank a)
{
long amt;
cout<<"Enter amount to be transferred: ";
cin>>amt;
a.balance=a.balance+amt;
if(balance<amt)
{
cout<<" Insufficient balance! Operation Cannot be performed!"<<endl<<endl;
}
else
{
balance=balance-amt;
}
return a;
}
void bank::withdrawal()
{
long amtdrawn;
cout<<"Enter amount to be withdrawn: ";
cin>>amtdrawn;
if(balance<amtdrawn)
cout<<" Insufficient balance! Operation Cannot be performed!"<<endl<<endl;
else
balance=balance-amtdrawn;
}
void bank::deposit()
{
long dep;
cout<<"Enter amount to be deposited: ";
cin>>dep;
balance+=dep;
}
void bank::newaccount()
{
accno++;
d.getdetails();
balance=0;
}
void bank::viewaccdetails()
{
cout<<endl<<endl<<"*********ASSIGNMENT BANK ACCOUNT DETAILS*********"<<endl;
cout<<" --- ---- ------- ------- "<<endl;
cout<<"Account no.: "<<accno<<endl;
cout<<"Name: "<<d.name<<endl;
cout<<"Branch: "<<d.branch<<endl;
cout<<"City: "<<d.city<<endl;
cout<<"Current Balance: "<<balance<<endl;
cout<<"_________________________________________"<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.