Wednesday, November 17, 2010

Banking Program Using BlueJ

This is the Banking program on transaction.

About the program



Initially Name, Account Number, Account type ( Savings / Current etc) and Initial Balance are taken for number of clients from user.
Minimum balance amount is Rs. 500.
In case of transaction Account number, mode of transaction (withdrwal or deposit), amount are taken from user. If it is withdrwal checking is done whether the balance permits the transaction.

User can enter any Account number and the current status of the Account will be displayed.



import java.io.*;
class Bank
{
String name[],amount[],ac[],acno[],particulars[],tran[][];
/* 'name' to hold names, 'amount' will hold initial amount, 'ac' will hold type of account
( savings / current etc) and 'acno' will hold account number, 'tran' will hold the transactions
'particulars' will hold the details of trasaction */
double dep; String actype;
/* 'dep' will hold the transaction amount and 'actype' will hold account type */
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int index=0;
/* it will be the index of the above declared arrays */
int tranindex=0;
/* it will be used in the transaction array */
Bank()
{
name=new String[50];
tran=new String[50][6];
particulars=new String[50];
amount=new String[50];
ac=new String[50];
acno=new String[50];
}
void initial()throws IOException
{
int i;
String date1;
String op="Yes";
while(!op.equalsIgnoreCase("No"))
{
System.out.println("Date:");
date1=br.readLine().toUpperCase();
System.out.println("Name:");
name[index]=br.readLine().toUpperCase();
//particulars[index]="B/F";
System.out.println("A/c No.:");
acno[index]=br.readLine().trim();
System.out.println("Initial Amount:");
amount[index]=br.readLine().trim();
System.out.println("Which type of A/c -(Press 'S' for Savings,'C' for Current,'R' for Recurring,'F' for Fixed deposit):");
ac[index]=br.readLine().trim().toUpperCase();
tran[tranindex][0]=date1;
tran[tranindex][1]="B/F";
tran[tranindex][2]=acno[index];
tran[tranindex][3]="d";
tran[tranindex][4]=amount[index];
tran[tranindex][5]=amount[index];
tranindex++;
System.out.println("Any More(Yes/No:):");
op=br.readLine().trim();
index++;
}
}
void transaction()throws IOException
{
int i;
double amount1; String date1,dep1,account;
String pat;
/* 'amount1' will hold the transaction amount, 'date1' to hold the transaction date,'dep1' will hold mode of transaction, 'account' will hold account number
'pat' will hold the particulars */
System.out.println("Enter the transaction type(d for deposit/w for withdrawal):");
dep1=br.readLine().trim().toLowerCase();
System.out.println("Enter the amount:");
amount1=Double.parseDouble(br.readLine());
System.out.println("Enter the Particulars:");
pat=br.readLine().trim();
System.out.println("A/c No.:");
account=br.readLine().trim();
System.out.println("Date of transaction:");
date1=br.readLine().trim();
for( i=0;i< index;i++)
{
if(account.equals(acno[i]))
break;
}
if(i==index)
System.out.println("This A/c No.does not exist:");
else
{
if(dep1.equals("w"))
{
if(Double.parseDouble(amount[i])-amount1<500)
{
System.out.println("Insufficient Balance");
}
else
{
amount[i]=String.valueOf(Double.parseDouble(amount[i])-amount1);
tran[tranindex][0]=date1;
tran[tranindex][1]=pat;
tran[tranindex][2]=account;
tran[tranindex][3]="w";
tran[tranindex][4]=String.valueOf(amount1);
tran[tranindex][5]=String.valueOf(amount[i]);
tranindex++;
}
}
else if(dep1.equals("d"))
{
amount[i]=String.valueOf(Double.parseDouble(amount[i])+amount1);
tran[tranindex][0]=date1; // date of transaction
tran[tranindex][1]=pat;// particulars
tran[tranindex][2]=account;// account number
tran[tranindex][3]="d";// mode of transaction
tran[tranindex][4]=String.valueOf(amount1); // transaction amount
tran[tranindex][5]=String.valueOf(amount[i]);// balance
tranindex++;
}
}
}
void display(String s1)
{
int i,j;
for(i=0;i< index;i++)
{
if(s1.equals(acno[i]))
break;
}
if(i==index)
System.out.println("A/C No. does not exist:");
else
{
System.out.println("Name of the A/C holder="+name[i]);
System.out.println("A/c No.:"+s1);
System.out.println("A/c type:"+ac[i]);
System.out.println("Balance Rs:"+amount[i]);
System.out.println("*******************\n");
System.out.println("Date Particulars Withdrawn Deposited Balance\n");
for(j=0;j< tranindex;j++)
{
if(s1.equals(tran[j][2]))
{
if(tran[j][1].equals("B/F"))
System.out.println(tran[j][0]+ " " + tran[j][1]+ " "+ tran[j][5]);
else if(tran[j][3].equals("w"))
System.out.println(tran[j][0]+ " " + tran[j][1]+ " "+tran[j][4]+" "+ tran[j][5]);
else if(tran[j][3].equals("d"))
System.out.println(tran[j][0]+ " " + tran[j][1]+ " "+tran[j][4]+" "+ tran[j][5]);
}
}

}
}
public static void main(String args[])throws IOException
{
String ans="yes";
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
Bank ob=new Bank();
ob.initial();
while(!ans.equalsIgnoreCase("No"))
{
ob.transaction();
System.out.println("Any More(Yes/No:):");
ans=br1.readLine().trim();
}
System.out.println("A/C Number to search:");
String s=br1.readLine().trim();
ob.display(s);
}
}

Related PostBlueJ Projects For ICSE Students

5 comments:

  1. ***MUST READ***
    there are 3 minor flaws in the program which didn't allow me to compile the program.

    the statement in the program to be corrected is:

    for (i=0;i

    you need to add

    <=index;i++)

    there is another one in the program if you search carefully

    another is of the same type except the variable is j. the mistyped command is:

    for (j=0;j

    also here you need to add

    <=index;j++)

    to it.
    that's it! these are the minor flaws that made the entire program incomplete. it will save time of debugging the program by reading this comment :)

    ReplyDelete
  2. Thanks for bringing these errors to my notice. Actually what happens, while posting programs in HTML editor, there should be a gap between '<' and the value right to it, otherwise the editor treats '<' as HTML tag and the next part disappears.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete

Subscribe via email

Enter your email address:

Delivered by FeedBurner