what's wrong with this code?
import java.rmi.*;
import java.rmi.Naming;
import java.io.*;
import java.util.Scanner;
public class CalculateClient
{
public static void main(String args[]) throws Exception
{
// Call registry for PowerService
CalculateInterface service = (CalculateInterface) Naming.lookup("rmi://localhost/CalculateInterface");
Scanner kb = new Scanner(System.in);
for (;;)
{
System.out.println
("1 - Calculate square");
System.out.println
("2 - Calculate power");
System.out.println
("3 - Exit");
System.out.println ("Choice : ");
String line = kb.readLine();
Integer choice = new Integer(line);
int value = choice.intValue();
switch (value)
{
case 1:
System.out.println ("Number : ");
double number = Double.parseDouble(kb.nextLine());
double squared = obj.square(number);
//line = din.readLine();
//System.out.println();
// choice = new Integer (line);
//value = choice.intValue();
// Call remote method
System.out.println ("Answer : " + service.square(value));
break;
case 2:
System.out.println ("Number : ");
double number = Double.parseDouble(kb.nextLine());
double squared = obj.pow(num1, num2);
//line = din.readLine();
// choice = new Integer (line);
//value = choice.intValue();
System.out.println ("Power : ");
// line = din.readLine();
// choice = new Integer (line);
//int power = choice.intValue();
// Call remote method
System.out.println ("Answer : " + service.power(value, power));
break;
case 3:
System.exit(0);
default :
System.out.println("Invalid option");
break;
}
}
}
}
my server goes this way:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface CalculateInterface extends Remote
{
// Calculate the square of a number
public double square (int number) throws RemoteException;
// Calculate the power of a number
public double power (int num1, int num2) throws RemoteException;
}
and my implementation code is:
import java.math.*;
import java.rmi.*;
import java.rmi.server.*;
public class CalculateImpl extends UnicastRemoteObject implements CalculateInterface
{
public CalculateImpl () throws RemoteException
{
super();
}
// Calculate the square of a number
public double square (int number) throws RemoteException
{
// String numrep = String.valueOf(number);
// double squared = new double (numrep);
// Square the number
double squared = Math.sqrt(number);
return squared;
}
public double power (int num1, int num2) throws RemoteException
{
// String numrep = String.valueOf(num1);
//double squared = new double (numrep);
double squared = Math.pow(num1,num2);
return squared;
}
public static void main ( String args[] ) throws Exception
{
// Create an instance of our power service server ...
CalculateImpl obj = new CalculateImpl();
System.out.println("Registering to Name Server...");
try
{
Naming.rebind ("CalculateInterface", obj);
} catch (Exception ex) {
System.err.println(ex);
System.exit(1);
}
System.out.println ("Registered...");
}
}
i hope someone can help...:confused: