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

ExamineExamine the following two classes. There are five errors that cause this

ID: 3681989 • Letter: E

Question

ExamineExamine the following two classes. There are five errors that cause this program to malfunction. Find and correct these errors. the following two classes. There are five errors that cause this program to malfunction. Find and correct these errors.

import java.io.*;
import java.net.*;

public class NewClient
{
static Socket s;
static DataInputStream reader;
static DataOutputStream writer;
static String userN = “user”;
static String userP = “password”;
static int permissions;
  
static final String IP =
“Localhost”;
static final int PORT = 9999;
  
public static void main
(String[] args)
{
try
{
s = new Socket(IP,PORT);
reader = new
DataInputStream
(s.getInputStream());
writer = new
DataOutputStream
(s.getOutputStream());
permissions = getLogin();
}
catch(Exception ex){}
}
  
public int getLogin()
{
writer.writeUTF(userN);
writer.writeUTF(userP);
int perm = reader.read();
return perm;
}
}

import java.io.*;

import java.net.*;

public class NewServer

{

    static ServerSocket s;

    static Socket cl;

    static DataInputStream reader;

    static DataOutputStream writer;

    static String userN;

    static String userP;

    static final int P_FULL = 1054;

    static final int P_GUEST = 1051;

   

    static final int PORT = 9876;

   

    public static void main

      (String[] args)

    {

        try

        {

            s = new ServerSocket

              (PORT);

            cl = s.accept();

            reader = new

              DataInputStream

              (cl.getInputStream());

            writer = new

              DataOutputStream

              (cl.getOutputStream());

            readUser();

        }

        catch (Exception ex){}

    }

   

    public void readUser()

    {

        userN = reader.readLine();

        userP = reader.readLine();

        int perm;

        if (userN.equals(“user”))

            perm = P_FULL;

        if (userN.equals(“guest”))

            perm = P_GUEST;

        writer.writeInt(perm);

    }

}

import java.io.*;

import java.net.*;

public class NewServer

{

    static ServerSocket s;

    static Socket cl;

    static DataInputStream reader;

    static DataOutputStream writer;

    static String userN;

    static String userP;

    static final int P_FULL = 1054;

    static final int P_GUEST = 1051;

   

    static final int PORT = 9876;

   

    public static void main

      (String[] args)

    {

        try

        {

            s = new ServerSocket

              (PORT);

            cl = s.accept();

            reader = new

              DataInputStream

              (cl.getInputStream());

            writer = new

              DataOutputStream

              (cl.getOutputStream());

            readUser();

        }

        catch (Exception ex){}

    }

   

    public void readUser()

    {

        userN = reader.readLine();

        userP = reader.readLine();

        int perm;

        if (userN.equals(“user”))

            perm = P_FULL;

        if (userN.equals(“guest”))

            perm = P_GUEST;

        writer.writeInt(perm);

    }

}

Explanation / Answer

Hi, Please find the below error free code.

NewClient.java

import java.io.*;
import java.net.*;
public class NewClient
{
static Socket s;
static DataInputStream reader;
static DataOutputStream writer;
static String userN = "user";
static String userP = "password";
static int permissions;
  
static final String IP =
"localhost";
static final int PORT = 9999;
  
public static void main
(String[] args)
{
try
{
s = new Socket(IP,PORT);
reader = new
DataInputStream
(s.getInputStream());
writer = new
DataOutputStream
(s.getOutputStream());
permissions = getLogin();
}
catch(Exception ex){}
}
  
public static int getLogin() throws Exception
{
writer.writeUTF(userN);
writer.writeUTF(userP);
int perm = reader.read();
return perm;
}
}

NewServer.java

import java.io.*;
import java.net.*;

public class NewServer
{
static ServerSocket s;
static Socket cl;
static DataInputStream reader;
static DataOutputStream writer;
static String userN;
static String userP;
static final int P_FULL = 1054;
static final int P_GUEST = 1051;

static final int PORT = 9876;

public static void main
(String[] args)
{
try
{
s = new ServerSocket
(PORT);
cl = s.accept();
reader = new
DataInputStream
(cl.getInputStream());
writer = new
DataOutputStream
(cl.getOutputStream());
readUser();
}
catch (Exception ex){}
}

public static void readUser() throws Exception
{
userN = reader.readLine();
userP = reader.readLine();
int perm = 0;
if (userN.equals("user"))
perm = P_FULL;
if (userN.equals("guest"))
perm = P_GUEST;
writer.writeInt(perm);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote