Thursday, March 26, 2009

java code for TestBanking

import java.io.*;
class Bank
{
Customer customers[];
int noOfcustomers;
public Bank()
{
customers = new Customer[20];
noOfcustomers=0;
}

public void addcustomer(String name)
{
int i=noOfcustomers++;
 customers[i]= new Customer(name);
}

public int getNumOfcustomers()
{
return noOfcustomers;
}
public Customer getCustomer(int customer_index)
{
return customers[customer_index-1];
}
}

 class Customer
{
String name;
public String toString()
{
return(name);
}

public Customer(String n )
{
name=n;
}
}

class Testbanking
{
public String acceptDetails() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println();
System.out.println("Enter the first name of customer");
String x=br.readLine();
System.out.println();
System.out.println();
System.out.println("Enter the second name of customer");
String y=br.readLine();
return (x+" "+y);
}
public static void main(String [] arr)throws IOException
{
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
Bank b = new Bank();
Testbanking tb=new Testbanking();
String choice;
do
{
b.addcustomer(tb.acceptDetails());
int number= b.getNumOfcustomers();
System.out.println("No of customers in the bank = "+number);
System.out.println();
for(int i=1;i<=number;i++)
System.out.println(b.getCustomer(i));
System.out.println();
System.out.println("Continue? Y/N");
choice=br1.readLine();
}
while(choice.toUpperCase().equals("Y"));
}
}

0 comments: