Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29
  1. #21
    javarishi is offline Member
    Join Date
    Apr 2008
    Posts
    91
    Rep Power
    0

    Default

    Hei Buddy, This Code You Need To Put Inside The Class.

    If you are a buiginner in java i suggest for Cathey Sierra HeadFirst java Book. Please Go Through It First.

  2. #22
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Quote Originally Posted by denisdoherty View Post
    When i put public void ReturnAverage (String Average) throws RemoteException
    {
    }
    You need to put this code in implementing class dear.

    If still you have doubt ..please post your interface and class code.


    sanjeev


  3. #23
    javarishi is offline Member
    Join Date
    Apr 2008
    Posts
    91
    Rep Power
    0

    Default

    Hei denisdoherty,
    Are You Done With The Problem? Any Help Required ?

  4. #24
    denisdoherty is offline Member
    Join Date
    Apr 2008
    Posts
    31
    Rep Power
    0

    Default

    I still cannot get the { error part. Do u want me to post the code inside the interface and the code in the class?

  5. #25
    javarishi is offline Member
    Join Date
    Apr 2008
    Posts
    91
    Rep Power
    0

    Default

    Yaah you paste it here.

  6. #26
    denisdoherty is offline Member
    Join Date
    Apr 2008
    Posts
    31
    Rep Power
    0

    Default

    The code that i have in the interface is.

    The first error that I am getting is highlighted in bold.

    The error hear is Interface methods cannot have body.

    Java Code:
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    
    interface Interface extends Remote{
    
        //Returns the Sum of the Number
        public void ReturnSum (String Sum) throws RemoteException
        [B]{[/B]
        }
        //Returns the Product of the Number    
        public void ReturnProduct (String Product) throws RemoteException
        {
        }
        //Returns the Average of the Number    
        public void ReturnAverage (String Average) throws RemoteException
        {
        }
    }//end Interface
    And the code that i have in the class is.

    The error that i am getting within this class is highlighted in bold.

    This error is Helper is not abstract and does not override abstract method ReturnAverage(java.lang.String) in Interface

    Java Code:
    import java.net.*;
    import java.io.*;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.RMISecurityManager;
    
    [B]public class Helper implements  Interface {[/B]
    
       private final int SIZE =10;
       private ASumList sumList[];
       private int serverPort;
       private int numNumber;
       private InetAddress serverHost;
       private StreamSocket mySocket;
      // private InetAddress serverHost;
       
       public Helper(){
           super();
           
           sumList = new ASumList [SIZE];
           numNumber = 0;
        }
    
        Helper(String hostName,String portNum) throws SocketException,
                         UnknownHostException, IOException {                              
           this.serverHost = InetAddress.getByName(hostName);
           this.serverPort = Integer.parseInt(portNum);
           //Instantiates a stream-mode socket and wait for a connection.
           this.mySocket = new StreamSocket(this.serverHost, this.serverPort); 
           System.out.println("Connection request made");
          
       } // end constructor
       
           
       public String getnumber( String message) throws SocketException, IOException{     
          String number = "", nextnumber="";;    
          mySocket.sendMessage( message);
          
           // now receive the names
          nextnumber = mySocket.receiveMessage();
          while (!nextnumber.equals("")) {
              number += nextnumber+" ";      
              nextnumber = mySocket.receiveMessage();
            }
          return number;
       } // end getnumber
        
    
       public synchronized int ReturnSum (){
           String list ="";
           for (int i = 0; i < numNumber; i++)
                list = list+ sumList[i].getSum();
                list.trim();
                return numNumber;
        }
        public synchronized int Returnproduct(){
            String list ="";
            for (int i =0;i<numNumber; i++)
                list = list+sumList[i].getSum();
                 list.trim();
                return numNumber;
            }
        
        public synchronized int ReturnAverage(){
            String list ="";
            for (int i = 0; i<numNumber; i++)
                list = list+sumList[i].getSum();
                list.trim();
                return numNumber;
            }
            public void done( ) throws SocketException, IOException{
          mySocket.close( );
       } // end done 
    } //end class
    Would be greatful if anyone can help.

    Thanks

  7. #27
    javarishi is offline Member
    Join Date
    Apr 2008
    Posts
    91
    Rep Power
    0

    Default

    I have made the necessary changes. Try To Compile It.

    Interface
    ----------

    import java.rmi.Remote;
    import java.rmi.RemoteException;

    interface Interface extends Remote{

    //Returns the Sum of the Number
    public void ReturnSum (String Sum) throws RemoteException;

    //Returns the Product of the Number
    public void ReturnProduct (String Product) throws RemoteException;

    //Returns the Average of the Number
    public void ReturnAverage (String Average) throws RemoteException;
    }//end Interface


    Class
    --------

    import java.net.*;
    import java.io.*;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.RMISecurityManager;

    public class Helper implements Interface {

    private final int SIZE =10;
    private ASumList sumList[];
    private int serverPort;
    private int numNumber;
    private InetAddress serverHost;
    private StreamSocket mySocket;
    // private InetAddress serverHost;

    public Helper(){
    super();

    sumList = new ASumList [SIZE];
    numNumber = 0;
    }

    Helper(String hostName,String portNum) throws SocketException,
    UnknownHostException, IOException {
    this.serverHost = InetAddress.getByName(hostName);
    this.serverPort = Integer.parseInt(portNum);
    //Instantiates a stream-mode socket and wait for a connection.
    this.mySocket = new StreamSocket(this.serverHost, this.serverPort);
    System.out.println("Connection request made");

    } // end constructor


    public String getnumber( String message) throws SocketException, IOException{
    String number = "", nextnumber="";;
    mySocket.sendMessage( message);

    // now receive the names
    nextnumber = mySocket.receiveMessage();
    while (!nextnumber.equals("")) {
    number += nextnumber+" ";
    nextnumber = mySocket.receiveMessage();
    }
    return number;
    } // end getnumber


    public synchronized int ReturnSum (){
    String list ="";
    for (int i = 0; i < numNumber; i++)
    list = list+ sumList[i].getSum();
    list.trim();
    return numNumber;
    }
    public synchronized int Returnproduct(){
    String list ="";
    for (int i =0;i<numNumber; i++)
    list = list+sumList[i].getSum();
    list.trim();
    return numNumber;
    }

    public synchronized int ReturnAverage(){
    String list ="";
    for (int i = 0; i<numNumber; i++)
    list = list+sumList[i].getSum();
    list.trim();
    return numNumber;
    }
    public void done( ) throws SocketException, IOException{
    mySocket.close( );
    } // end done

    //Returns the Sum of the Number
    public void ReturnSum (String Sum) throws RemoteException
    {
    }
    //Returns the Product of the Number
    public void ReturnProduct (String Product) throws RemoteException
    {
    }
    //Returns the Average of the Number
    public void ReturnAverage (String Average) throws RemoteException
    {
    }
    } //end class

    Any Further Queries, let me know.

  8. #28
    denisdoherty is offline Member
    Join Date
    Apr 2008
    Posts
    31
    Rep Power
    0

    Default

    that has compiled now thanks very much.

  9. #29
    javarishi is offline Member
    Join Date
    Apr 2008
    Posts
    91
    Rep Power
    0

    Default

    Ok Good. Always welcome for good Questions. We all should learn and

    improve. Try to read the book which i have suggested.

Page 2 of 2 FirstFirst 12

Posting Permissions

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