SlideShare a Scribd company logo
1 of 8
Download to read offline
Write the following using java
Given a class ‘Node’ and ‘NodeList’, that contains the below information diagram.
-id: int
-name: String
-next: Node
+Node(id: int, name: String)
+setId(id: int): void
+getId(): int
+setName(name: String) : void
+getName(): String
+setNext(node: Node): void
+getNext(): Node
NodeList
-size: int
-root: Node
+add(node: Node): void
+size(): int
+findNode(node: Node): boolean
Implement add(Node), findNode(Node) and size methods in the NodeList class which is
provided to you. The methods should work as:
Using the following main method:
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);
System.out.println("Length : "+list.size());
Node node3 = new Node(3, "Glass");
Node node4 = new Node(4, "Pen");
list.add(node3);
System.out.println("Length : "+list.size());
if(list.findNode(node3)) System.out.println("Node found: "+ node3.getName());
else
System.out.println("Node not found: "+ node3.getName());
if(list.findNode(node4)) System.out.println("Node found: "+ node4.getName());
else
System.out.println("Node not found: "+ node4.getName());
}
Then it should return the following output:
Length : 2
Length : 3
Node found: Glass
Node not found: Pen
The given Node class is:
public class Node
{
private int id = 0;
private String name = "";
private Node next;
public Node(int id, String name)
{
this.id = id;
this.name = name;
this.next = null;
}
public Node getNext()
{
return next;
}
public void setNext(Node node)
{
this.next = 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;
}
}
The given NodeList class is:
public class NodeList
{
private int size = 0;
private Node root = null;
/*
* It has to take a new Node and add that to the next address of previous Node.
* If the list is empty, assign it as the "root"
* @Param - Node
*/
public void add(Node node)
{
// Implement this method!!!
}
/*
* It has to return the size of the NodeList
*
* @return size
*/
public int size()
{
// Implement this method!!!
}
/*
* It has to take a Node and checks if the node is in the list.
* If it finds the node, it returns true, otherwise false
*
* @param - Node
* @return boolean true/false
*/
public boolean findNode(Node node)
{
// Implement this method!!!
}
}Node
-id: int
-name: String
-next: Node
+Node(id: int, name: String)
+setId(id: int): void
+getId(): int
+setName(name: String) : void
+getName(): String
+setNext(node: Node): void
+getNext(): Node
Solution
Hi, Please find my implementation.
Please let me know in case of any issue.
############ Node.java #############
public class Node
{
private int id = 0;
private String name = "";
private Node next;
public Node(int id, String name)
{
this.id = id;
this.name = name;
this.next = null;
}
public Node getNext()
{
return next;
}
public void setNext(Node node)
{
this.next = 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;
}
}
################ NodeList.java ########################
public class NodeList
{
private int size = 0;
private Node root = null;
/*
* It has to take a new Node and add that to the next address of previous Node.
* If the list is empty, assign it as the "root"
* @Param - Node
*/
public void add(Node node)
{
// Implement this method!!!
if(root == null)
root = node;
else{
node.setNext(root); // adding at front
root = node;
}
size++;
}
/*
* It has to return the size of the NodeList
*
* @return size
*/
public int size()
{
// Implement this method!!!
return size;
}
/*
* It has to take a Node and checks if the node is in the list.
* If it finds the node, it returns true, otherwise false
*
* @param - Node
* @return boolean true/false
*/
public boolean findNode(Node node)
{
// Implement this method!!!
Node temp = root;
while(temp != null){
if(temp.getId() == node.getId() &&
temp.getName().equalsIgnoreCase(node.getName()))
return true;
temp = temp.getNext();
}
return false;
}
}
################ NodeListTest.java ########################
public class NodeListTest {
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);
System.out.println("Length : "+list.size());
Node node3 = new Node(3, "Glass");
Node node4 = new Node(4, "Pen");
list.add(node3);
System.out.println("Length : "+list.size());
if(list.findNode(node3)) System.out.println("Node found: "+ node3.getName());
else
System.out.println("Node not found: "+ node3.getName());
if(list.findNode(node4)) System.out.println("Node found: "+ node4.getName());
else
System.out.println("Node not found: "+ node4.getName());
}
}
/*
Sample run:
Length : 2
Length : 3
Node found: Glass
Node not found: Pen
*/

More Related Content

Similar to Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf

How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
 
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdfmain.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdfpratikradia365
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfarjunstores123
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
 
Please write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdfPlease write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdfamarndsons
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfStewart29UReesa
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docxajoy21
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfstopgolook
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdffathimafancyjeweller
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdffmac5
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked listSourav Gayen
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfAnkitchhabra28
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfmail931892
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdfshanki7
 

Similar to Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf (20)

How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdfmain.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdf
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
Please write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdfPlease write the C++ code that would display the exact same output a.pdf
Please write the C++ code that would display the exact same output a.pdf
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdf
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
 

More from fathimalinks

Write a program in C++ that declares a structure to store the code n.pdf
Write a program in C++ that declares a structure to store the code n.pdfWrite a program in C++ that declares a structure to store the code n.pdf
Write a program in C++ that declares a structure to store the code n.pdffathimalinks
 
Write a generic VBA Sub procedure to compute the value of the follow.pdf
Write a generic VBA Sub procedure to compute the value of the follow.pdfWrite a generic VBA Sub procedure to compute the value of the follow.pdf
Write a generic VBA Sub procedure to compute the value of the follow.pdffathimalinks
 
Why are standards needed in data communication and networking What .pdf
Why are standards needed in data communication and networking What .pdfWhy are standards needed in data communication and networking What .pdf
Why are standards needed in data communication and networking What .pdffathimalinks
 
Which of the following are mismatched A. Giordia - transmitted by f.pdf
Which of the following are mismatched  A. Giordia - transmitted by f.pdfWhich of the following are mismatched  A. Giordia - transmitted by f.pdf
Which of the following are mismatched A. Giordia - transmitted by f.pdffathimalinks
 
Which of the following statements about human evolution is correct.pdf
Which of the following statements about human evolution is correct.pdfWhich of the following statements about human evolution is correct.pdf
Which of the following statements about human evolution is correct.pdffathimalinks
 
What are the six major pollutions in the National Ambient Air Qualit.pdf
What are the six major pollutions in the National Ambient Air Qualit.pdfWhat are the six major pollutions in the National Ambient Air Qualit.pdf
What are the six major pollutions in the National Ambient Air Qualit.pdffathimalinks
 
UPS Worldpart DiscussionWhat do you think are the operational str.pdf
UPS Worldpart DiscussionWhat do you think are the operational str.pdfUPS Worldpart DiscussionWhat do you think are the operational str.pdf
UPS Worldpart DiscussionWhat do you think are the operational str.pdffathimalinks
 
True or False Justify your answer.Using multilevel signaling, it .pdf
True or False Justify your answer.Using multilevel signaling, it .pdfTrue or False Justify your answer.Using multilevel signaling, it .pdf
True or False Justify your answer.Using multilevel signaling, it .pdffathimalinks
 
This is question about excel cuers wish to answer shortly how to use.pdf
This is question about excel cuers wish to answer shortly how to use.pdfThis is question about excel cuers wish to answer shortly how to use.pdf
This is question about excel cuers wish to answer shortly how to use.pdffathimalinks
 
There is a requirement to design a system to sense the presence of gl.pdf
There is a requirement to design a system to sense the presence of gl.pdfThere is a requirement to design a system to sense the presence of gl.pdf
There is a requirement to design a system to sense the presence of gl.pdffathimalinks
 
The investments of Charger Inc. include a single investment 11,010 .pdf
The investments of Charger Inc. include a single investment 11,010 .pdfThe investments of Charger Inc. include a single investment 11,010 .pdf
The investments of Charger Inc. include a single investment 11,010 .pdffathimalinks
 
RNA polymerasebinds to DNA after the double strands have been unwoun.pdf
RNA polymerasebinds to DNA after the double strands have been unwoun.pdfRNA polymerasebinds to DNA after the double strands have been unwoun.pdf
RNA polymerasebinds to DNA after the double strands have been unwoun.pdffathimalinks
 
Research and explain the deviant actions of the Los Angeles Police D.pdf
Research and explain the deviant actions of the Los Angeles Police D.pdfResearch and explain the deviant actions of the Los Angeles Police D.pdf
Research and explain the deviant actions of the Los Angeles Police D.pdffathimalinks
 
Question 1 10 points Save A TALIA Contribute NINA Co Contribute TALIA.pdf
Question 1 10 points Save A TALIA Contribute NINA Co Contribute TALIA.pdfQuestion 1 10 points Save A TALIA Contribute NINA Co Contribute TALIA.pdf
Question 1 10 points Save A TALIA Contribute NINA Co Contribute TALIA.pdffathimalinks
 
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdfQ1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdffathimalinks
 
Please revise the answer bellow.Q1. What historically have been Ap.pdf
Please revise the answer bellow.Q1. What historically have been Ap.pdfPlease revise the answer bellow.Q1. What historically have been Ap.pdf
Please revise the answer bellow.Q1. What historically have been Ap.pdffathimalinks
 
Negligence Curtis R. Wilhelm owned beehives and kept the hives on pr.pdf
Negligence Curtis R. Wilhelm owned beehives and kept the hives on pr.pdfNegligence Curtis R. Wilhelm owned beehives and kept the hives on pr.pdf
Negligence Curtis R. Wilhelm owned beehives and kept the hives on pr.pdffathimalinks
 
List and explain at least three popular sixteenth century dance type.pdf
List and explain at least three popular sixteenth century dance type.pdfList and explain at least three popular sixteenth century dance type.pdf
List and explain at least three popular sixteenth century dance type.pdffathimalinks
 
Introduction to Database Management SystemConsider the following .pdf
Introduction to Database Management SystemConsider the following .pdfIntroduction to Database Management SystemConsider the following .pdf
Introduction to Database Management SystemConsider the following .pdffathimalinks
 
In female mammals, one of the X chromosomes in each cell is condensed.pdf
In female mammals, one of the X chromosomes in each cell is condensed.pdfIn female mammals, one of the X chromosomes in each cell is condensed.pdf
In female mammals, one of the X chromosomes in each cell is condensed.pdffathimalinks
 

More from fathimalinks (20)

Write a program in C++ that declares a structure to store the code n.pdf
Write a program in C++ that declares a structure to store the code n.pdfWrite a program in C++ that declares a structure to store the code n.pdf
Write a program in C++ that declares a structure to store the code n.pdf
 
Write a generic VBA Sub procedure to compute the value of the follow.pdf
Write a generic VBA Sub procedure to compute the value of the follow.pdfWrite a generic VBA Sub procedure to compute the value of the follow.pdf
Write a generic VBA Sub procedure to compute the value of the follow.pdf
 
Why are standards needed in data communication and networking What .pdf
Why are standards needed in data communication and networking What .pdfWhy are standards needed in data communication and networking What .pdf
Why are standards needed in data communication and networking What .pdf
 
Which of the following are mismatched A. Giordia - transmitted by f.pdf
Which of the following are mismatched  A. Giordia - transmitted by f.pdfWhich of the following are mismatched  A. Giordia - transmitted by f.pdf
Which of the following are mismatched A. Giordia - transmitted by f.pdf
 
Which of the following statements about human evolution is correct.pdf
Which of the following statements about human evolution is correct.pdfWhich of the following statements about human evolution is correct.pdf
Which of the following statements about human evolution is correct.pdf
 
What are the six major pollutions in the National Ambient Air Qualit.pdf
What are the six major pollutions in the National Ambient Air Qualit.pdfWhat are the six major pollutions in the National Ambient Air Qualit.pdf
What are the six major pollutions in the National Ambient Air Qualit.pdf
 
UPS Worldpart DiscussionWhat do you think are the operational str.pdf
UPS Worldpart DiscussionWhat do you think are the operational str.pdfUPS Worldpart DiscussionWhat do you think are the operational str.pdf
UPS Worldpart DiscussionWhat do you think are the operational str.pdf
 
True or False Justify your answer.Using multilevel signaling, it .pdf
True or False Justify your answer.Using multilevel signaling, it .pdfTrue or False Justify your answer.Using multilevel signaling, it .pdf
True or False Justify your answer.Using multilevel signaling, it .pdf
 
This is question about excel cuers wish to answer shortly how to use.pdf
This is question about excel cuers wish to answer shortly how to use.pdfThis is question about excel cuers wish to answer shortly how to use.pdf
This is question about excel cuers wish to answer shortly how to use.pdf
 
There is a requirement to design a system to sense the presence of gl.pdf
There is a requirement to design a system to sense the presence of gl.pdfThere is a requirement to design a system to sense the presence of gl.pdf
There is a requirement to design a system to sense the presence of gl.pdf
 
The investments of Charger Inc. include a single investment 11,010 .pdf
The investments of Charger Inc. include a single investment 11,010 .pdfThe investments of Charger Inc. include a single investment 11,010 .pdf
The investments of Charger Inc. include a single investment 11,010 .pdf
 
RNA polymerasebinds to DNA after the double strands have been unwoun.pdf
RNA polymerasebinds to DNA after the double strands have been unwoun.pdfRNA polymerasebinds to DNA after the double strands have been unwoun.pdf
RNA polymerasebinds to DNA after the double strands have been unwoun.pdf
 
Research and explain the deviant actions of the Los Angeles Police D.pdf
Research and explain the deviant actions of the Los Angeles Police D.pdfResearch and explain the deviant actions of the Los Angeles Police D.pdf
Research and explain the deviant actions of the Los Angeles Police D.pdf
 
Question 1 10 points Save A TALIA Contribute NINA Co Contribute TALIA.pdf
Question 1 10 points Save A TALIA Contribute NINA Co Contribute TALIA.pdfQuestion 1 10 points Save A TALIA Contribute NINA Co Contribute TALIA.pdf
Question 1 10 points Save A TALIA Contribute NINA Co Contribute TALIA.pdf
 
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdfQ1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
 
Please revise the answer bellow.Q1. What historically have been Ap.pdf
Please revise the answer bellow.Q1. What historically have been Ap.pdfPlease revise the answer bellow.Q1. What historically have been Ap.pdf
Please revise the answer bellow.Q1. What historically have been Ap.pdf
 
Negligence Curtis R. Wilhelm owned beehives and kept the hives on pr.pdf
Negligence Curtis R. Wilhelm owned beehives and kept the hives on pr.pdfNegligence Curtis R. Wilhelm owned beehives and kept the hives on pr.pdf
Negligence Curtis R. Wilhelm owned beehives and kept the hives on pr.pdf
 
List and explain at least three popular sixteenth century dance type.pdf
List and explain at least three popular sixteenth century dance type.pdfList and explain at least three popular sixteenth century dance type.pdf
List and explain at least three popular sixteenth century dance type.pdf
 
Introduction to Database Management SystemConsider the following .pdf
Introduction to Database Management SystemConsider the following .pdfIntroduction to Database Management SystemConsider the following .pdf
Introduction to Database Management SystemConsider the following .pdf
 
In female mammals, one of the X chromosomes in each cell is condensed.pdf
In female mammals, one of the X chromosomes in each cell is condensed.pdfIn female mammals, one of the X chromosomes in each cell is condensed.pdf
In female mammals, one of the X chromosomes in each cell is condensed.pdf
 

Recently uploaded

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 

Recently uploaded (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 

Write the following using javaGiven a class ‘Node’ and ‘NodeList’,.pdf

  • 1. Write the following using java Given a class ‘Node’ and ‘NodeList’, that contains the below information diagram. -id: int -name: String -next: Node +Node(id: int, name: String) +setId(id: int): void +getId(): int +setName(name: String) : void +getName(): String +setNext(node: Node): void +getNext(): Node NodeList -size: int -root: Node +add(node: Node): void +size(): int +findNode(node: Node): boolean Implement add(Node), findNode(Node) and size methods in the NodeList class which is provided to you. The methods should work as: Using the following main method: 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); System.out.println("Length : "+list.size()); Node node3 = new Node(3, "Glass"); Node node4 = new Node(4, "Pen"); list.add(node3); System.out.println("Length : "+list.size()); if(list.findNode(node3)) System.out.println("Node found: "+ node3.getName()); else
  • 2. System.out.println("Node not found: "+ node3.getName()); if(list.findNode(node4)) System.out.println("Node found: "+ node4.getName()); else System.out.println("Node not found: "+ node4.getName()); } Then it should return the following output: Length : 2 Length : 3 Node found: Glass Node not found: Pen The given Node class is: public class Node { private int id = 0; private String name = ""; private Node next; public Node(int id, String name) { this.id = id; this.name = name; this.next = null; } public Node getNext() { return next; } public void setNext(Node node) { this.next = node } public int getId() { return id; {
  • 3. 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; } } The given NodeList class is: public class NodeList { private int size = 0; private Node root = null; /* * It has to take a new Node and add that to the next address of previous Node. * If the list is empty, assign it as the "root" * @Param - Node */ public void add(Node node) { // Implement this method!!!
  • 4. } /* * It has to return the size of the NodeList * * @return size */ public int size() { // Implement this method!!! } /* * It has to take a Node and checks if the node is in the list. * If it finds the node, it returns true, otherwise false * * @param - Node * @return boolean true/false */ public boolean findNode(Node node) { // Implement this method!!! } }Node -id: int -name: String -next: Node +Node(id: int, name: String) +setId(id: int): void +getId(): int
  • 5. +setName(name: String) : void +getName(): String +setNext(node: Node): void +getNext(): Node Solution Hi, Please find my implementation. Please let me know in case of any issue. ############ Node.java ############# public class Node { private int id = 0; private String name = ""; private Node next; public Node(int id, String name) { this.id = id; this.name = name; this.next = null; } public Node getNext() { return next; } public void setNext(Node node) { this.next = node ; } public int getId() { return id; } public void setId(int id) { this.id = id;
  • 6. } public String getName() { return name; } public void setName(String name) { this.name = name; } public String toString() { return "ID : "+this.id+" Name : "+this.name; } } ################ NodeList.java ######################## public class NodeList { private int size = 0; private Node root = null; /* * It has to take a new Node and add that to the next address of previous Node. * If the list is empty, assign it as the "root" * @Param - Node */ public void add(Node node) { // Implement this method!!! if(root == null) root = node; else{ node.setNext(root); // adding at front root = node; } size++; }
  • 7. /* * It has to return the size of the NodeList * * @return size */ public int size() { // Implement this method!!! return size; } /* * It has to take a Node and checks if the node is in the list. * If it finds the node, it returns true, otherwise false * * @param - Node * @return boolean true/false */ public boolean findNode(Node node) { // Implement this method!!! Node temp = root; while(temp != null){ if(temp.getId() == node.getId() && temp.getName().equalsIgnoreCase(node.getName())) return true; temp = temp.getNext(); } return false; } } ################ NodeListTest.java ######################## public class NodeListTest { public static void main(String[] args) { NodeList list = new NodeList();
  • 8. Node node = new Node(1, "Book"); Node node2 = new Node(2, "Lappy"); list.add(node); list.add(node2); System.out.println("Length : "+list.size()); Node node3 = new Node(3, "Glass"); Node node4 = new Node(4, "Pen"); list.add(node3); System.out.println("Length : "+list.size()); if(list.findNode(node3)) System.out.println("Node found: "+ node3.getName()); else System.out.println("Node not found: "+ node3.getName()); if(list.findNode(node4)) System.out.println("Node found: "+ node4.getName()); else System.out.println("Node not found: "+ node4.getName()); } } /* Sample run: Length : 2 Length : 3 Node found: Glass Node not found: Pen */