5 Rmi Print

578 views

Published on

rmi

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
578
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

5 Rmi Print

  1. 1. IMPLEMENTATION OR RMI ARITHMETIC OPERATIONS /* cal.java*/ import java.rmi.*; public interface cal extends Remote { public int add(int x,int y) throws RemoteException; public int sub(int x,int y) throws RemoteException; public int mul(int x,int y) throws RemoteException; public int div(int x,int y) throws RemoteException; } /* calimp.java*/ import java.rmi.*; import java.rmi.server.*; import java.io.*; public class calimp extends UnicastRemoteObject implements cal { public calimp() throws RemoteException { super(); } public int add(int x,int y) throws RemoteException { return x+y; } public int sub(int x,int y) throws RemoteException { return x-y; } public int mul(int x,int y) throws RemoteException { return x*y; } public int div(int x,int y) throws RemoteException { return x/y; } } /* calserver.java*/ import java.rmi.*; import java.rmi.server.*; public class calserver
  2. 2. { public static void main(String args[]) { try { calimp c=new calimp(); System.out.println("Binding Server implementation to registry .."); Naming.rebind("WIN",c); System.out.println("Registered"); System.out.println("Waiting for client to connect ..."); } catch(Exception e) { e.printStackTrace(); } } } /* calclient.java*/ import java.rmi.*; import java.rmi.server.*; import java.io.*; public class calclient { public static void main(String args[]) throws Exception { int a,b; DataInputStream d =new DataInputStream(System.in); boolean f=false; String url="rmi://localhost/"; try { cal c = (cal) Naming.lookup(url+"WIN"); do { System.out.println("nCALCULATOR"); System.out.println(" 1.Add"); System.out.println(" 2.Subtract"); System.out.println(" 3.Multiply"); System.out.println(" 4.Divide"); System.out.println(" 5.Exit"); System.out.print("nEnter your choice : "); switch(Integer.parseInt(d.readLine())) { case 1:
  3. 3. System.out.print("nADDITION"); System.out.print("nNumber 1t: "); a=Integer.parseInt(d.readLine()); System.out.print("Number 2t: "); b=Integer.parseInt(d.readLine()); System.out.println("Sumtt: " + c.add(a,b)); break; case 2: System.out.print("nSUBTRACTION"); System.out.print("nNumber 1t: "); a=Integer.parseInt(d.readLine()); System.out.print("Number 2t: "); b=Integer.parseInt(d.readLine()); System.out.println("Differencet: " + c.sub(a,b)); break; case 3: System.out.print("nMULTIPLICATION"); System.out.print("nNumber 1t: "); a=Integer.parseInt(d.readLine()); System.out.print("Number 2t: "); b=Integer.parseInt(d.readLine()); System.out.println("Producttt: " + c.mul(a,b)); break; case 4: System.out.print("nDIVISION"); System.out.print("nNumber 1t: "); a=Integer.parseInt(d.readLine()); System.out.print("Number 2t: "); b=Integer.parseInt(d.readLine()); System.out.println("Quotientt: " + c.div(a,b)); break; case 5: System.out.print("nProgram Terminatednn"); f=true; break; } d.readLine(); }while(!f); } catch(Exception e) { System.out.println("Error"); } } }
  4. 4. OUTPUT: CALCULATOR 1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit Enter your choice : 1 ADDITION Number 1 : 23 Number 2 : 34 Sum : 57 CALCULATOR 1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit Enter your choice : 2 SUBTRACTION Number 1 : 45 Number 2 : 11 Difference : 34 CALCULATOR 1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit Enter your choice : 3 MULTIPLICATION Number 1 : 45 Number 2 :3 Product : 135
  5. 5. CALCULATOR 1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit Enter your choice : 4 DIVISION Number 1 : 32 Number 2 : 16 Quotient :2 CALCULATOR 1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit Enter your choice : 5 Program Terminated

×