Advertisement
Guest User

rmi calculator

a guest
Sep 1st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.54 KB | None | 0 0
  1.  
  2. import java.rmi.RemoteException;
  3. import java.rmi.server.UnicastRemoteObject;
  4. import java.util.Scanner;
  5.  
  6. public class Implement extends UnicastRemoteObject implements Chatting
  7. {
  8.  
  9.     public String[] r;
  10.     public String o = "", o1 = "", o2 = "";
  11.  
  12.     public Implement() throws RemoteException
  13.     {
  14.         super();
  15.     }
  16.  
  17.     @Override
  18.     public String getMessage() throws RemoteException
  19.     {
  20.         Scanner sc = new Scanner(System.in);
  21.         System.out.print("My Message: ");
  22.         //String message = sc.next();
  23.         String message = "";
  24.         if (o.equals("+"))
  25.         {
  26.             message = Double.toString(Double.parseDouble(o1) + Double.parseDouble(o2));
  27.         }
  28.         else if (o.equals("-"))
  29.         {
  30.             message = Double.toString(Double.parseDouble(o1) - Double.parseDouble(o2));
  31.         }
  32.         else if (o.equals("*"))
  33.         {
  34.             message = Double.toString(Double.parseDouble(o1) * Double.parseDouble(o2));
  35.         }
  36.         else if (o.equals("/"))
  37.         {
  38.             try
  39.             {
  40.                 message = Double.toString(Double.parseDouble(o1) / Double.parseDouble(o2));
  41.             }
  42.             catch (Exception e)
  43.             {
  44.                 message = e.getMessage();
  45.             }
  46.         }
  47.         return message;
  48.     }
  49.  
  50.     @Override
  51.     public void sendMessage(String s) throws RemoteException
  52.     {
  53.         System.out.println("Client's Message: " + s);
  54.         r = s.split(":");
  55.         o1 = r[0];
  56.         o2 = r[1];
  57.         o = r[2];
  58.  
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement