Results 1 to 6 of 6
  1. #1
    agenteleven is offline Member
    Join Date
    Oct 2008
    Posts
    8
    Rep Power
    0

    Talking 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:

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  3. #3
    agenteleven is offline Member
    Join Date
    Oct 2008
    Posts
    8
    Rep Power
    0

    Default

    in the code i pasted before, is my switch statement correct? it keeps on displaying an error message "cannot find symbol symbol : method readLine"

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    On this line,

    Java Code:
    line = din.readLine();
    What's mean by din. Where are you define it? I can't see that you've define it in your code.

  5. #5
    agenteleven is offline Member
    Join Date
    Oct 2008
    Posts
    8
    Rep Power
    0

    Default

    i made it a comment so the program won't read it.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

    Default

    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(); //<---
    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.

    db

Similar Threads

  1. Can someone tell me what I did wrong??
    By booter4429 in forum New To Java
    Replies: 7
    Last Post: 08-13-2008, 08:35 PM
  2. what is wrong with this code
    By masaka in forum New To Java
    Replies: 5
    Last Post: 04-16-2008, 08:27 AM
  3. What's wrong with this code?
    By Wizard wusa in forum New To Java
    Replies: 14
    Last Post: 01-22-2008, 11:55 PM
  4. Is there somethign wrong with this code?
    By Soda in forum New To Java
    Replies: 1
    Last Post: 12-08-2007, 04:46 PM
  5. Whats wrong with my code???
    By Soda in forum New To Java
    Replies: 2
    Last Post: 12-06-2007, 12:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •