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: net bean coding railway reservation, bean recipes, develop marketing, matrix operations using grid java**t, import, matrix operations using grid java, how to develop missing vehicle project in vb net,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  Simple Key Events Java source code smart paper boy 3 3,582 07-02-2017, 03:41 PM
Last Post: NARESHLAFOOT
  Window Events Java source code smart paper boy 1 3,660 02-03-2012, 10:48 AM
Last Post: seminar paper
  Inter net banking java source code smart paper boy 3 5,927 01-03-2012, 11:24 AM
Last Post: seminar paper
  UDP server java source code smart paper boy 1 3,801 05-01-2012, 05:50 PM
Last Post: jeslinapeter
  UDP client Java source code smart paper boy 2 3,660 12-12-2011, 09:56 AM
Last Post: seminar addict
  Text Demo Java source code smart paper boy 0 2,069 30-08-2011, 12:44 PM
Last Post: smart paper boy
  Text Area Demo Java source code smart paper boy 0 2,076 30-08-2011, 12:44 PM
Last Post: smart paper boy
  Servlet Database Java source code smart paper boy 0 2,453 30-08-2011, 12:42 PM
Last Post: smart paper boy
  server test Java source code smart paper boy 0 2,257 30-08-2011, 12:42 PM
Last Post: smart paper boy
  Ser To App java source code smart paper boy 0 1,671 30-08-2011, 12:39 PM
Last Post: smart paper boy

Forum Jump: