import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;


public class CalcClient {
	double a,b;
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	
	public CalcClient(){
		System.out.print("\n***Welcome to CalcClient!***\n"
				+ " Type me some math and my friend CalcServer will tell you the answer!!\n\n"
				+ "Be careful everything must be space-separated! Something like this \"+ 3 5\" \n ");
	}

	public static void main(String[] args) {
		CalcClient client = new CalcClient();
		boolean terminate = false;
		double result = 0;
		String op; //operation
		
		try {
			Registry registry = LocateRegistry.getRegistry(4444); //localhost is used as default
			CalcInterface calc = (CalcInterface) registry.lookup("RMICalculator");
			
			while(!terminate) {
				op = client.userInput();
				if( op.equals("+")) {
					result = calc.Add(client.a, client.b);
					System.out.println("Result = "+result);
				}
				else if (op.equals("-")){
					result = calc.Subtract(client.a, client.b);
					System.out.println("Result = "+result);
				}
				else if (op.equals("*")) {
					result = calc.Multiply(client.a, client.b);
					System.out.println("Result = "+result);
				}
				else if (op.equals("/")) {
					result = calc.Divide(client.a, client.b);
					System.out.println("Result = "+result);
				}
				else if (op.equals("exit")) {
					System.out.println("\nGoodByeeee!!");
					break;
				} else {
					System.out.println("\nWrong Input\n");
				}
			}
			
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	
	public String  userInput(){
		System.out.print("Enter message: ");
		String msg;
		try {
			msg = in.readLine();
			if(!msg.equals("exit")){
				String[] expression = msg.split(" ");
				a = Double.parseDouble(expression[1]);
				b = Double.parseDouble(expression[2]);
				return expression[0];
			} else {
				return "exit" ;
			}
		} catch (IOException e) {
			System.out.println("User Input failed");
			e.printStackTrace();
			return null;
		}
		
	}

}

@@ -2000,16 +2000,31 @@
 Line();%0A
+%09%09%09msg.trim();%0A
 %09%09%09if(!m
@@ -2039,24 +2039,24 @@
 s(%22exit%22))%7B%0A
-
 %09%09%09%09String%5B%5D
@@ -2081,24 +2081,170 @@
 split(%22 %22);%0A
+%09%09%09%09if(expression.length == 3)%7B%0A%09%09%09%09%09if (expression%5B0%5D.matches(%22%5B+%5C%5C-*/%5D%22) && expression%5B1%5D.matches(%22%5C%5Cd+%22) && expression%5B2%5D.matches(%22%5C%5Cd+%22) )%7B%0A%09%09
 %09%09%09%09a = Doub
@@ -2270,24 +2270,26 @@
 ession%5B1%5D);%0A
+%09%09
 %09%09%09%09b = Doub
@@ -2319,24 +2319,26 @@
 on%5B2%5D);%0A%09%09%09%09
+%09%09
 return expre
@@ -2347,16 +2347,29 @@
 ion%5B0%5D;%0A
+%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A
 %09%09%09%7D els
@@ -2509,20 +2509,38 @@
 n null;%0A
-
 %09%09%7D%0A
+%09%09return %22error%22;%0A
 %09%09%0A%09%7D%0A%0A%7D

improved input handling. now it is immune to invalid input