Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
To develop an Enterprise Java Bean for banking operations
#1

Aim : To develop an Enterprise Java Bean for banking operations
Algorthm :
1. Create four programs- Bankbean, Bankhome, Bank, and Bankclient
2. In the Bankbean class first define the prototypes of the various methods
3. Next, provide the implementation for ejbCreate(), ejbPostCreate(), credit(), and debit() methods
4. In the Bankhome class just invoke the methods create() and findbyprimarykey() with the respective number of arguments
5. In the Bankremote class just define the prototypes of the various methods which throws the Remoteexception
6. In the Bankclient class, display the options to the user and use the lookup() method and perform the operations accordingly

Program
Bank-Remote Interface
Code:
import javax.ejb.*;
import java.rmi.*;
import java.util.*;
public interface BankRemote extends EJBObject
{

  public Integer getCusid() throws  RemoteException;
  public void setBal(double balance) throws  RemoteException;
  public double getBal() throws  RemoteException;
  public void debit(double amount) throws  RemoteException;
  public void credit(double amount) throws  RemoteException;
}
Bank-Home interface

import java.io.*;
import java.rmi.RemoteException;
import javax.ejb.*;
public interface BankHome extends EJBHome
{
public BankRemote create(Integer empid,double balance) throws RemoteException,CreateException;
public BankRemote findByPrimaryKey(Integer cusid) throws FinderException,RemoteException;
}

Bank-Bean class
Code:
import javax.rmi.*;
import javax.ejb.*;
public abstract class BankBean implements EntityBean
{
public double cbalance;
public double amount;
public double balance;
public EntityContext context,ctx;
public Integer id;
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbRemove() {}
public void ejbLoad(){}
public void ejbStore(){}
public void setEntityContext(EntityContext ctx) {}
public void unsetEntityContext() {}
public abstract void setCusid(Integer cusid);
public abstract Integer getCusid();
public abstract void setBal(double balance);
public abstract double getBal();
public Integer ejbCreate(Integer cusid,double balance)
{
setCusid(cusid);
setBal(balance);
return null;
}
public void ejbPostCreate(Integer cusid,double balance){}
public void debit(double amount)
{
balance = getBal();
balance-= amount;
setBal(balance);
}
public void credit(double amount)
{
balance = getBal();
balance+=amount;
setBal(balance);
}
}

Bank Client
Code:
import javax.naming.*;
import javax.rmi.*;
import java.rmi.*;
import java.io.*;
import java.util.*;
import javax.ejb.*;
public class BankClient
{
public static void main(String arg[])
{
int cid;
double cbalance;
int ch;
double camount;
try
{
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
  "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,
  "t3://localhost:7001");
p.put(Context.SECURITY_PRINCIPAL,"rec");
p.put(Context.SECURITY_CREDENTIALS,
  "mcastudent");
InitialContext ict = new InitialContext(p);
System.out.println("Context sucessful");
Object t = ict.lookup("BankBean1");
System.out.println("Lookup successful");
BankHome h = (BankHome)PortableRemoteObject.narrow(t,BankHome.class);
System.out.println("Home stub obtained");
try
{
System.out.println("\n 1.CREATE \n2. CREDIT \n3. DEBIT \n4. BALANCE \n5. EXIT");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1: System.out.println("\nEnter the account number: ");
cid = Integer.parseInt(br.readLine());
System.out.println("\nEnter Initial amount: ");
camount = Integer.parseInt(br.readLine());
BankRemote e = h.create(new Integer(cid),camount);
System.out.println("Successfully inserted");
break;
case 2: System.out.println("\nEnter the account number: ");
cid = Integer.parseInt(br.readLine());
  BankRemote c = h.findByPrimaryKey(new Integer(cid));
System.out.println("\nEnter the amount: ");
camount = Integer.parseInt(br.readLine());
  c.credit(camount);
cbalance = c.getBal();
System.out.println("Available balance: "+cbalance);
break;
case 3: System.out.println("\nEnter the account number: ");
cid = Integer.parseInt(br.readLine());
  BankRemote d = h.findByPrimaryKey(new Integer(cid));
System.out.println("\nEnter the amount: ");
camount = Integer.parseInt(br.readLine());
  d.debit(camount);
  cbalance = d.getBal();
System.out.println("Available balance: "+cbalance);
break;
case 4: System.out.println("\nEnter the account number: ");
cid = Integer.parseInt(br.readLine());
  BankRemote b = h.findByPrimaryKey(new Integer(cid));
  cbalance = b.getBal();
System.out.println("Available balance: "+cbalance);
break;
}
}
catch(IOException e)
{
System.out.println("Exception invoked");
}
catch(Exception e)
{
System.out.println("Invalid Customer ID");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: develop an ejb for banking operations program, develop an enterprise java bean for banking operations program, java program to create a java bean to draw various graphical shapes and display it using or without using bdk, develop an enterprise java bean program for library operations, how is the adoption of an enterprise security framework helpful for developing an enterprise security policy, develop an enterprise java bean for library operations programs, java program to draw graphical shapes using java bean,

Forum Jump:


Users browsing this thread: 1 Guest(s)