Advertisement
MayurTolani

RMI

Apr 25th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. import java.rmi.*;
  2. public interface Stationery extends Remote
  3. {
  4.     public boolean available(String prod)throws RemoteException;
  5.     int bill(String prod,int qty)throws RemoteException;
  6.     String goodbye()throws RemoteException;
  7. }
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. import java.rmi.*;
  10. import java.rmi.server.*;
  11. public class StationeryImplementation extends UnicastRemoteObject implements Stationery
  12. {
  13.     String products[]={"Pen","Apsara Pencil","Natraj Pencil"};
  14.     int quanty[]={10,10,10};
  15.     int price[]={100,5,4};
  16.     StationeryImplementation()throws RemoteException
  17.     {
  18.        
  19.     }
  20.     public boolean available(String prod)throws RemoteException
  21.     {
  22.         for(int i=0;i<products.length;i++)
  23.             if(prod.equalsIgnoreCase(products[i])) 
  24.                 return true;
  25.         return false;
  26.     }
  27.     public int bill(String prod,int qty)throws RemoteException
  28.     {
  29.         int amount=0;
  30.         for(int i=0;i<products.length;i++)
  31.             if(prod.equalsIgnoreCase(products[i])) 
  32.                 if(qty<=quanty[i])
  33.                 {
  34.                     amount+=price[i]*qty;
  35.                 }
  36.         return amount;
  37.     }
  38.     public String goodbye()throws RemoteException
  39.     {
  40.         return "Thank You";
  41.     }
  42. }////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  43.  
  44.  
  45. import java.rmi.*;
  46. import java.rmi.server.*;
  47. public class StationeryServer
  48. {
  49.     public static void main(String args[])throws Exception
  50.     {
  51.         StationeryImplementation si=new StationeryImplementation();
  52.         Naming.rebind("Stats",si);
  53.     }
  54. }
  55. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  56.  
  57. import java.rmi.*;
  58. import java.io.*;
  59. public class StationeryClient
  60. {
  61.     public static void main(String args[])throws Exception
  62.     {
  63.         Stationery st=(Stationery)Naming.lookup("rmi://localhost/Stats");
  64.         System.out.println(st.available("Pen"));
  65.         System.out.println(st.bill("Pen",5));
  66.         System.out.println(st.goodbye());
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement