Monday, October 12, 2009

client

import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;

import java.util.Scanner;


public class client
{
public static Scanner in = new Scanner(System.in);
public static inter server;
public static Registry registry;

public static double a,
b;
public static String choice;
public static String cont;



static public void main(String[] par)
{

try
{
registry = LocateRegistry.getRegistry("localhost", 3333);
//registry = LocateRegistry.getRegistry(serverAddress, (new Integer(serverPort)).intValue());

server = (inter)(registry.lookup("serverop"));


do
{
do
{
System.out.println("\n\tPlease select operation.");
System.out.println("\t 1. Addition.");
System.out.println("\t 2. Subtraction.");
System.out.println("\t 3. Multiplication.");
System.out.println("\t 4. Division.");

System.out.print("\tYour choice : "); choice = in.nextLine();

if(!((choice.equals("1"))||(choice.equals("2"))||(choice.equals("3"))||(choice.equals("4"))))
{ System.out.println("You have entered an invalid choice."); }

}while(!((choice.equals("1"))||(choice.equals("2"))||(choice.equals("3"))||(choice.equals("4"))));




System.out.print("\tYour first number : "); a = Double.parseDouble(in.nextLine());
System.out.print("\tYour second number : "); b = Double.parseDouble(in.nextLine());

System.out.println("The result : " + server.operate(a, b, Integer.parseInt(choice)));
System.out.println("Do you want to continue [Y / N] : "); cont = in.nextLine();




}while(cont.equals("Y")||cont.equals("y"));
}

catch(RemoteException e)
{
e.printStackTrace();
}
catch(NotBoundException e)
{
e.printStackTrace();
}


}
}

No comments:

Post a Comment