SlideShare a Scribd company logo
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 (20)

Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
alicesilverblr
 
In this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdfIn this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdf
fantasiatheoutofthef
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
alphaagenciesindia
 
Objective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfObjective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdf
aliracreations
 
Fix my codeCode.pdf
Fix my codeCode.pdfFix my codeCode.pdf
Fix my codeCode.pdf
Conint29
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
seoagam1
 
Can someone help me to fix the code please package dlist i.pdf
Can someone help me to fix the code please package dlist i.pdfCan someone help me to fix the code please package dlist i.pdf
Can someone help me to fix the code please package dlist i.pdf
ABHISHEKREADYMADESKO
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
fcaindore
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
aamousnowov
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdf
sales88
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
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
Ankitchhabra28
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
advancethchnologies
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
giriraj65
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
archgeetsenterprises
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfLinked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdf
adityacomputers001
 
Use the singly linked list class introduced in the lab to implement .pdf
Use the singly linked list class introduced in the lab to implement .pdfUse the singly linked list class introduced in the lab to implement .pdf
Use the singly linked list class introduced in the lab to implement .pdf
sales87
 
-JAVA-provide a test class that do the required -you may add met.pdf
-JAVA-provide a test class that do the required -you may add met.pdf-JAVA-provide a test class that do the required -you may add met.pdf
-JAVA-provide a test class that do the required -you may add met.pdf
alphawheels007
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
alicesilverblr
 
In this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdfIn this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdf
fantasiatheoutofthef
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
alphaagenciesindia
 
Objective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfObjective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdf
aliracreations
 
Fix my codeCode.pdf
Fix my codeCode.pdfFix my codeCode.pdf
Fix my codeCode.pdf
Conint29
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
seoagam1
 
Can someone help me to fix the code please package dlist i.pdf
Can someone help me to fix the code please package dlist i.pdfCan someone help me to fix the code please package dlist i.pdf
Can someone help me to fix the code please package dlist i.pdf
ABHISHEKREADYMADESKO
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
fcaindore
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
aamousnowov
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdf
sales88
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
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
Ankitchhabra28
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
advancethchnologies
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
giriraj65
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
archgeetsenterprises
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfLinked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdf
adityacomputers001
 
Use the singly linked list class introduced in the lab to implement .pdf
Use the singly linked list class introduced in the lab to implement .pdfUse the singly linked list class introduced in the lab to implement .pdf
Use the singly linked list class introduced in the lab to implement .pdf
sales87
 
-JAVA-provide a test class that do the required -you may add met.pdf
-JAVA-provide a test class that do the required -you may add met.pdf-JAVA-provide a test class that do the required -you may add met.pdf
-JAVA-provide a test class that do the required -you may add met.pdf
alphawheels007
 

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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
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.pdf
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 
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
fathimalinks
 

Recently uploaded (20)

Policies, procedures, subject selection and QTAC.pptx
Policies, procedures, subject selection and QTAC.pptxPolicies, procedures, subject selection and QTAC.pptx
Policies, procedures, subject selection and QTAC.pptx
mansk2
 
NA FASE REGIONAL DO TL – 1.º CICLO. .
NA FASE REGIONAL DO TL – 1.º CICLO.     .NA FASE REGIONAL DO TL – 1.º CICLO.     .
NA FASE REGIONAL DO TL – 1.º CICLO. .
Colégio Santa Teresinha
 
Post Exam Fun(da)- a General under-25 quiz, Prelims and Finals
Post Exam Fun(da)- a General  under-25 quiz, Prelims and FinalsPost Exam Fun(da)- a General  under-25 quiz, Prelims and Finals
Post Exam Fun(da)- a General under-25 quiz, Prelims and Finals
Pragya - UEM Kolkata Quiz Club
 
Combustion in Compression Ignition Engine (CIE)
Combustion in Compression Ignition Engine (CIE)Combustion in Compression Ignition Engine (CIE)
Combustion in Compression Ignition Engine (CIE)
NileshKumbhar21
 
Product in Wartime: How to Build When the Market Is Against You
Product in Wartime: How to Build When the Market Is Against YouProduct in Wartime: How to Build When the Market Is Against You
Product in Wartime: How to Build When the Market Is Against You
victoriamangiantini1
 
Protest - Student Revision Booklet For VCE English
Protest - Student Revision Booklet For VCE EnglishProtest - Student Revision Booklet For VCE English
Protest - Student Revision Booklet For VCE English
jpinnuck
 
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
EduSkills OECD
 
From Building Products to Owning the Business
From Building Products to Owning the BusinessFrom Building Products to Owning the Business
From Building Products to Owning the Business
victoriamangiantini1
 
Module I. Democracy, Elections & Good Governance
Module I. Democracy, Elections & Good GovernanceModule I. Democracy, Elections & Good Governance
Module I. Democracy, Elections & Good Governance
srkmcop0027
 
The Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional DesignThe Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional Design
Sean Michael Morris
 
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-21-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-21-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-21-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-21-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Intervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without MicromanagingIntervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without Micromanaging
victoriamangiantini1
 
Basic principles involved in the traditional systems of medicine, Chapter 7,...
Basic principles involved in the traditional systems of medicine,  Chapter 7,...Basic principles involved in the traditional systems of medicine,  Chapter 7,...
Basic principles involved in the traditional systems of medicine, Chapter 7,...
ARUN KUMAR
 
Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Amit Kumar Sahoo
 
AI and international projects. Helsinki 20.5.25
AI and international projects. Helsinki 20.5.25AI and international projects. Helsinki 20.5.25
AI and international projects. Helsinki 20.5.25
Matleena Laakso
 
The Board Doesn’t Care About Your Roadmap: Running Product at the Board
The Board Doesn’t Care About Your Roadmap: Running Product at the BoardThe Board Doesn’t Care About Your Roadmap: Running Product at the Board
The Board Doesn’t Care About Your Roadmap: Running Product at the Board
victoriamangiantini1
 
Letter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. SenatorsLetter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. Senators
Mebane Rash
 
How to create Record rules in odoo 18 - Odoo Slides
How to create Record rules in odoo 18 - Odoo  SlidesHow to create Record rules in odoo 18 - Odoo  Slides
How to create Record rules in odoo 18 - Odoo Slides
Celine George
 
5503 Course Proposal Online Computer Middle School Course Wood M.pdf
5503 Course Proposal Online Computer Middle School Course Wood M.pdf5503 Course Proposal Online Computer Middle School Course Wood M.pdf
5503 Course Proposal Online Computer Middle School Course Wood M.pdf
Melanie Wood
 
Policies, procedures, subject selection and QTAC.pptx
Policies, procedures, subject selection and QTAC.pptxPolicies, procedures, subject selection and QTAC.pptx
Policies, procedures, subject selection and QTAC.pptx
mansk2
 
Post Exam Fun(da)- a General under-25 quiz, Prelims and Finals
Post Exam Fun(da)- a General  under-25 quiz, Prelims and FinalsPost Exam Fun(da)- a General  under-25 quiz, Prelims and Finals
Post Exam Fun(da)- a General under-25 quiz, Prelims and Finals
Pragya - UEM Kolkata Quiz Club
 
Combustion in Compression Ignition Engine (CIE)
Combustion in Compression Ignition Engine (CIE)Combustion in Compression Ignition Engine (CIE)
Combustion in Compression Ignition Engine (CIE)
NileshKumbhar21
 
Product in Wartime: How to Build When the Market Is Against You
Product in Wartime: How to Build When the Market Is Against YouProduct in Wartime: How to Build When the Market Is Against You
Product in Wartime: How to Build When the Market Is Against You
victoriamangiantini1
 
Protest - Student Revision Booklet For VCE English
Protest - Student Revision Booklet For VCE EnglishProtest - Student Revision Booklet For VCE English
Protest - Student Revision Booklet For VCE English
jpinnuck
 
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
EduSkills OECD
 
From Building Products to Owning the Business
From Building Products to Owning the BusinessFrom Building Products to Owning the Business
From Building Products to Owning the Business
victoriamangiantini1
 
Module I. Democracy, Elections & Good Governance
Module I. Democracy, Elections & Good GovernanceModule I. Democracy, Elections & Good Governance
Module I. Democracy, Elections & Good Governance
srkmcop0027
 
The Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional DesignThe Pedagogy We Practice: Best Practices for Critical Instructional Design
The Pedagogy We Practice: Best Practices for Critical Instructional Design
Sean Michael Morris
 
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup - Microsoft Discontinuation of Selected Cloud Donated Offers 2025.05...
TechSoup
 
Intervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without MicromanagingIntervene with Precision: Zooming In as a Leader Without Micromanaging
Intervene with Precision: Zooming In as a Leader Without Micromanaging
victoriamangiantini1
 
Basic principles involved in the traditional systems of medicine, Chapter 7,...
Basic principles involved in the traditional systems of medicine,  Chapter 7,...Basic principles involved in the traditional systems of medicine,  Chapter 7,...
Basic principles involved in the traditional systems of medicine, Chapter 7,...
ARUN KUMAR
 
Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Quality Assurance and Quality Management, B. Pharm 6th Semester-Unit-1
Amit Kumar Sahoo
 
AI and international projects. Helsinki 20.5.25
AI and international projects. Helsinki 20.5.25AI and international projects. Helsinki 20.5.25
AI and international projects. Helsinki 20.5.25
Matleena Laakso
 
The Board Doesn’t Care About Your Roadmap: Running Product at the Board
The Board Doesn’t Care About Your Roadmap: Running Product at the BoardThe Board Doesn’t Care About Your Roadmap: Running Product at the Board
The Board Doesn’t Care About Your Roadmap: Running Product at the Board
victoriamangiantini1
 
Letter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. SenatorsLetter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. Senators
Mebane Rash
 
How to create Record rules in odoo 18 - Odoo Slides
How to create Record rules in odoo 18 - Odoo  SlidesHow to create Record rules in odoo 18 - Odoo  Slides
How to create Record rules in odoo 18 - Odoo Slides
Celine George
 
5503 Course Proposal Online Computer Middle School Course Wood M.pdf
5503 Course Proposal Online Computer Middle School Course Wood M.pdf5503 Course Proposal Online Computer Middle School Course Wood M.pdf
5503 Course Proposal Online Computer Middle School Course Wood M.pdf
Melanie Wood
 

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 */