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

import com.list.Node; import com.list.NodeList; public class Main { public stati

ID: 3673512 • Letter: I

Question


import com.list.Node;
import com.list.NodeList;

public class Main {

public static void main(String[] args) {

NodeList list = new NodeList();
Node node = new Node(1, "Book");
Node node2 = new Node(2, "Lappy");

list.add(node);
list.add(node2);
list.add(node);
list.add(node2);
System.out.println("Length : "+list.size());

list.remove(node);
System.out.println("Length : "+list.size());
list.remove(node2);

Node node3 = new Node(3, "Glass");
list.remove(node3);
System.out.println("Length : "+list.size());

}
}

package com.list;

public class NodeList {

private int size = 0;
private Node root = null;;

/*
* It has to take a new Node and add that to the address og previous Node.
*
* @Param - Node
*/
public void add(Node node) {

}

/*
* It has to return the size of the NodeList
*
* @return size
*/
public int size() {
return size;
}

/*
* It has to take a Node and remove that node if you find it in the list
* from the existing nodes otherwise dont do anything.
*
* @Param - Node
*/

public void remove(Node node) {
}
}

package com.list;

public class Node {

private int id = 0;
private String name = "";
private Node node;

public Node(int id, String name) {
this.id = id;
this.name = name;
this.node = null;
}

public Node getNode() {
return node;
}

public void setNode(Node node) {
this.node = node;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String toString() {
return "ID : "+this.id+" Name : "+this.name;
}
}

Explanation / Answer

Please find the full implementation below :