import java.io.*;
import java.net.*;
import java.util.concurrent.locks.*;

public class Chat {
	public boolean done = false;
	private ServerSocket listener;
	private Socket socket;

	public static void main(String[] args) {

		try {
			System.out.println("My IP Address: " + InetAddress.getLocalHost());
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}

		Chat chat = new Chat();

		// For debugging
		String hostname = "";
		int port = 9090;
		try {
			hostname = InetAddress.getLocalHost().getHostName();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}

		chat.run(hostname, port);
	}

	public void run(String hostname, int port) {
		try {
			Socket socket = this.setupConnection(hostname, port);
			Thread receiver = new Thread(new Receiver(socket));
			receiver.start();
			PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
			out.println("Hello world");
			System.out.println("Connected");
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			boolean done = false;
			do {
				out.println(br.readLine());
				synchronized (this) {
					done = this.done;
				}
			} while (!done);

			socket.close();
			listener.close();
			System.out.println("Done");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public Socket setupConnection(String hostname, int port) throws IOException {
		// this.listener = new ServerSocket(port);
		return new Socket(hostname, port);
	}

	public void createNodeNetwork() {

	}

	public void joinNodeNetwork() {

	}

	public void sendString(String text) {

	}

	private class Receiver implements Runnable {
		Socket socket;

		public Receiver(Socket socket) {
			this.socket = socket;
		}

		@Override
		public void run() {
			try {
				System.out.println("Thread Run");
				BufferedReader in = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
				String message = in.readLine();
				while (message != "exit") {
					System.out.println("Incoming message: " + message);
				}

				synchronized (Chat.this) {
					Chat.this.done = true;
				}
				System.out.println("Thread exit");
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		public void receiveString(String text, int nodeId) {

		}

		public void addNode(int nodeId) {

		}

	}

}

@@ -72,16 +72,133 @@
 s.*;%0D%0A%0D%0A
+/**%0D%0A * A node that joins a network and sends and receives messages from other nodes.%0D%0A * %0D%0A * @author Jeanine%0D%0A */%0D%0A
 public c
@@ -754,32 +754,196 @@
 , port);%0D%0A%09%7D%0D%0A%0D%0A
+%09/**%0D%0A%09 * Main method for the node. Sends messages to and listens messages%0D%0A%09 * from other nodes in the network.%0D%0A%09 * %0D%0A%09 * @param hostname%0D%0A%09 * @param port%0D%0A%09 */%0D%0A
 %09public void run
@@ -1972,154 +1972,456 @@
 %0A%0D%0A%09
-private class Receiver implements Runnable %7B%0D%0A%09%09Socket socket;%0D%0A%0D%0A%09%09public Receiver(Socket socket) %7B%0D%0A%09%09%09this.socket = socket;%0D%0A%09%09%7D%0D%0A%0D%0A%09%09@Override
+/**%0D%0A%09 * Receives incoming messages from other nodes in the network.%0D%0A%09 * %0D%0A%09 * @author Jeanine%0D%0A%09 */%0D%0A%09private class Receiver implements Runnable %7B%0D%0A%09%09Socket socket;%0D%0A%0D%0A%09%09/**%0D%0A%09%09 * Initializes a new instance of the Receiver class.%0D%0A%09%09 * @param socket%0D%0A%09%09 */%0D%0A%09%09public Receiver(Socket socket) %7B%0D%0A%09%09%09this.socket = socket;%0D%0A%09%09%7D%0D%0A%0D%0A%09%09@Override%0D%0A%09%09/**%0D%0A%09%09 * Keeps listening for data from other nodes and executes%0D%0A%09%09 * the corresponding actions.%0D%0A%09%09 */
 %0D%0A%09%09
@@ -2908,69 +2908,269 @@
 %0D%0A%09%09
-public void receiveString(String text, int nodeId) %7B%0D%0A%0D%0A%09%09%7D%0D%0A
+/**%0D%0A%09%09 * Handles an incoming message from another node.%0D%0A%09%09 * @param text%0D%0A%09%09 * @param nodeId%0D%0A%09%09 */%0D%0A%09%09public void receiveString(String text, int nodeId) %7B%0D%0A%0D%0A%09%09%7D%0D%0A%0D%0A%09%09/**%0D%0A%09%09 * Handles the introduction of a new node to the network.%0D%0A%09%09 * @param nodeId%0D%0A%09%09 */
 %0D%0A%09%09
@@ -3185,16 +3185,19 @@
 oid addN
+ewN
 ode(int 

Add code documentation to classes and functions.