Results 1 to 6 of 6
Thread: what's wrong with this code?
- 10-07-2008, 10:47 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 8
- Rep Power
- 0
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:
- 10-07-2008, 10:54 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you tell me what's your question is. I hope most of members are lazy to run your code and fix errors if any. Please ask your questions specifically.
- 10-07-2008, 10:58 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 8
- Rep Power
- 0
in the code i pasted before, is my switch statement correct? it keeps on displaying an error message "cannot find symbol symbol : method readLine"
- 10-07-2008, 11:08 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
On this line,
What's mean by din. Where are you define it? I can't see that you've define it in your code.Java Code:line = din.readLine();
- 10-07-2008, 11:12 AM #5
Member
- Join Date
- Oct 2008
- Posts
- 8
- Rep Power
- 0
i made it a comment so the program won't read it.
- 10-07-2008, 11:26 AM #6
Well when I read the API for Scanner I don't see a method readLine() so I wouldn't expect the compiler to find one either.Java Code: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(); //<---
db
Similar Threads
-
Can someone tell me what I did wrong??
By booter4429 in forum New To JavaReplies: 7Last Post: 08-13-2008, 08:35 PM -
what is wrong with this code
By masaka in forum New To JavaReplies: 5Last Post: 04-16-2008, 08:27 AM -
What's wrong with this code?
By Wizard wusa in forum New To JavaReplies: 14Last Post: 01-22-2008, 11:55 PM -
Is there somethign wrong with this code?
By Soda in forum New To JavaReplies: 1Last Post: 12-08-2007, 04:46 PM -
Whats wrong with my code???
By Soda in forum New To JavaReplies: 2Last Post: 12-06-2007, 12:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks