Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Examine the following two classes. Complete the server’s receiveData() method. D

ID: 3679566 • Letter: E

Question

Examine the following two classes. Complete the server’s receiveData() method. Do not change anything in the client class. Assume all imports and variables are properly set up.

public class NewClient

{

    Socket s;

    DataInputStream reader;

    DataOutputStream writer;

    String userN;

    String userP;

    int health;

    float exp;

    boolean sent;

   

    public static void main

      (String[] args)

    {

        try{ sendData(); }

        catch(Exception ex){}

    }

   

    sendData()

    {

        //Send username

        writer.writeUTF(userN);

       

        //Send password

        writer.writeUTF(userP);

       

        //Send health

        writer.writeInt(health);

       

        //Send experience

        writer.writeFloat(exp);

       

        //Confirm data sent

        sent =

          reader.readBoolean();

    }

}

public class NewServer

{

    ServerSocket s;

    DataInputStream reader;

    DataOutputStream writer;

    String userN;

    String userP;

    int health;

    float exp;

   

    public static void main

      (String[] args)

    {

        try { receiveData(); }

        catch (Exception ex){}

    }

   

    receiveData()

    {

        //Write your code here!

   

    }

}

public class NewClient

{

    Socket s;

    DataInputStream reader;

    DataOutputStream writer;

    String userN;

    String userP;

    int health;

    float exp;

    boolean sent;

   

    public static void main

      (String[] args)

    {

        try{ sendData(); }

        catch(Exception ex){}

    }

   

    sendData()

    {

        //Send username

        writer.writeUTF(userN);

       

        //Send password

        writer.writeUTF(userP);

       

        //Send health

        writer.writeInt(health);

       

        //Send experience

        writer.writeFloat(exp);

       

        //Confirm data sent

        sent =

          reader.readBoolean();

    }

}

public class NewServer

{

    ServerSocket s;

    DataInputStream reader;

    DataOutputStream writer;

    String userN;

    String userP;

    int health;

    float exp;

   

    public static void main

      (String[] args)

    {

        try { receiveData(); }

        catch (Exception ex){}

    }

   

    receiveData()

    {

        //Write your code here!

   

    }

}

Explanation / Answer

   receiveData()

    {


       userN=br.readLine();
       userP=br.readLine();
       health=Interger.parseInt(reader.readLine());
       exp=Integer.parseInt(reader.readLine());

    }