SlideShare a Scribd company logo
1 of 8
Download to read offline
need this program in java please and thanks!
NOTICE: There are NO static variables allowed in this lab. The only class that a static method is
allowed is in the TestDriver class. The only static method that you actually really need is main.
The purpose of this lab is to give you an opportunity to create your own linked list data structure
and implement all the methods specified below to do list operations. The following specifies the
linked list class which you must implement. Only implement the methods listed below. Do NOT
add any additional member variables. class OrderedLinkedList { private class Node { // NOTE:
The member variables are public so the methods // of the OrderedLinkedList class have direct
access to them // NO setters and getters are needed – more efficient access. public String
payload; public int keyValue; public Node next; // Explicit value constructor for the Node class
public Node(String payload, int value) { …. } } private Node first; // This is the only member
variable allowed. // You can NOT add any other member variables!!!
public OrderedLinkedList ( ) { … } // default constructor public boolean empty( ) { … } //
returns true if list is empty public String getFirst( ) throws Exception { … } // The first node is
removed from the list and its payload is returned. // An exception with a meaningful error
message is thrown if the list is empty. public String getLast( ) throws Exception { … } // The last
node is removed from the list and its payload is returned. // An exception with a meaningful error
message is thrown if the list is empty. public void insert(String payload, int key) throws
Exception { … } // The insert method creates a new node, puts the input parameter values // into
the new node, and then inserts the node into the list in sorted order // based on the keyValue. For
example, if a list has 3 nodes with key values // of 5, 10, and 15, insertion of a new node which
has a key value of 12 would // require that the new node was inserted after the node with key
value of 10. // If the key being inserted is already in the list, throw an Exception with a //
meaningful error string. Make sure that you test all possible cases for insertion. public void
remove(int key) throws Exception { … } // Traverse the list, keeping track of where the
precedessor for each node // is located. When the value is found in some node in the list, make
the // predecessor node bypass the node which holds the value. If the key value // is not found,
throw an Exception that indicates the error has occurred. public int listCount( ) { … } // Returns
the number of nodes in the list. public String getValue(int key) throws Exception { … } //
Traverse the list until you locate the requested key value. Return the // payload from the node
which has the requested key value. If the key value // is not found, throw an Exception that
indicates the error has occurred. public String toString( ) { … } // Override the toString method
and create a string that contains the information // from all the nodes currently in the list. The
string should be constructed such // that the data from each node will appear on a separate line. If
the list is empty // the returned string should indicate that the list was empty. } Implement all the
methods of this class and write a test program which thoroughly tests all of the methods in this
class. Carefully consider each method and what meaningful test cases are needed to fully test
each method. Make sure to identify each test case in your test driver class with a comment. You
can write your test program any way you like, but your program must thoroughly exercise your
class. Running the test program one time must result in the successful execution of every test
case. It can be interactive with the user, or just have some specific hardwired test cases. Make
sure that the output generated by your test program clearly indicates what each of your test cases
is doing and what the results are. By running your test program one time, you should be
convinced that every method of your class is running correctly under all circumstances. Your
grade will partially be determined by how good of a job you do in testing your class. Make sure
to test all the exception cases! Documentation You must provide complete documentation for the
OrderedLinkedList class. Javadoc comments must be provided at the class level that include the
author plus an overview of the purpose of the class. Javadoc comments must be provided for
each method of the OrderedLinkedList class. The method level comments must include
parameter explanations, return explanations, and exception explanations. Any preconditions
should be explained with the parameters and exceptions, and postconditions should be explained
with the return. You must generate the Javadoc documentation from your comments. You do this
by clicking on Run in the NetBeans menu bar. Then click on Generate Javadoc. An HTML page
will appear that contains all the comments extracted from the classes in your project. There
should be no errors when running the Javadoc tool. Development Strategy Setup your project
with the OrderedLinkedList class with all the methods specified containing no code so that the
class compiles initially. You will need dummy return statements in some of the methods to get
things to compile. Set up your test driver program to create an OrderedLinkedList object. Work
on the insert method first followed by the toString method. Once you get those two methods
written, you can start adding test cases to your test program to add items to the list and then use
the toString method to return the content of the list to be displayed by your test program. Debug
and test these methods first before moving on to the other methods. Once these methods are
working, then implement and test one OrderedLinkedList class method at a time.
Solution
This is the program
package LinkedList;
import java.sql.SQLException;
/**
OrderedLinkedList class is for implementing linked list
Basic functions such as getFirstNode, remove, insert are implemented.
*/
public class OrderedLinkedList {
/**
The Node class which contains a payload , a key and a next.
next will hold the next node in the linked list
*/
private class Node{
public String payload;
public int keyvalue;
public Node next;
/**
* default constructor for the Node class
* @param payload - contains the string value
* @param keyvalue - integer value which represents a key
*/
public Node(String payload, int keyvalue)
{
this.payload = payload;
this.keyvalue = keyvalue;
}
}
private Node first;
public OrderedLinkedList()
{
}
/**
* checks whether the list is empty
* @return true or false indicating whether the list is empty
*/
public boolean empty()
{
boolean isEmpty = false;
if(first == null)
{
isEmpty = true;
}
return isEmpty;
}
/**
* find the first element in the list
* @throws throws an exception if the list doesnt contain elements
* @return return the payload for the first node
*/
public String getFirst( ) throws Exception{
String Mypayload = "";
try{
Mypayload = first.payload;
}
catch (Exception e) {
// TODO: handle exception
System.out.println("The list is empty.");
}
return Mypayload;
}
/**
* find the last element in the list
* @throws throws an exception if the list doesnt contain elements
* @return return the payload for the last node
*/
public String getLast( ) throws Exception
{
String mypayload = "";
Node nodes = first;
while(nodes.next != null)
{
nodes = nodes.next;
}
try{
mypayload = nodes.payload;
}catch(Exception e)
{
System.out.println("List is empty");
}
return mypayload;
}
/**
* inserts element in the list by arranging the keys in ascending order
* @param payload - the string to be inserted in the node
* @param key - a unique key value
* @throws throws an exception if the list doesnt contain elements
*/
public void insert(String payload, int key) throws Exception{
if(first == null)
{
first = new Node(payload, key);
first.next = null;
}
else
{
while(first.next != null)
{
if(first.keyvalue > key)
{
Node Currentnode = first;
Currentnode.keyvalue = key;
Currentnode.payload = payload;
Currentnode.next = first;
}
else
{
first = first.next;
}
}
Node node = new Node(payload, key);
first.next = node;
}
}
/**
* removes an element from the list
* @throws throws an exception if the list doesnt contain elements
* @param key - the unique key to be searched
*/
public void remove(int key) throws Exception {
while(first.next!=null)
{
if(first.keyvalue == key)
{
Node nextNode = first.next;
first.keyvalue = nextNode.keyvalue;
first.payload = nextNode.payload;
first.next = nextNode.next;
}
else
{
first = first.next;
}
}
}
/**
* finds the total size of the list
* @return integer - count of nodes in the list
*/
public int listCount( ) {
int count = 0;
if(!empty())
{
while(first.next != null)
{
count++;
first = first.next;
}
}
return count;
}
/**
* finds the value of the key by traversing through the list
* @throws throws an exception if the list doesnt contain elements
* @return string - payload of the key
*/
public String getValue(int key) throws Exception {
String value = "";
while(first.next!=null)
{
if(first.keyvalue == key)
{
try{
value = first.payload;
}
catch(Exception e)
{
System.out.println("Try again.");
}
}
else
{
first = first.next;
}
}
return value;
}
/**
* displays the value of the payloads by traversing through the list
* @return string - payload of the key
*/
public String toString( ) {
String values = "";
while(first.next != null)
{
values = values + first.payload + " ";
first = first.next;
}
return values;
}
}
This is the main class
package LinkedList;
public class TestDriver {
public static void main(String[] args) throws Exception
{
OrderedLinkedList list = new OrderedLinkedList();
list.insert("Apple", 2);
list.getFirst();
list.getLast();
list.insert("Mango", 1);
list.getValue(2);
}
}
Output:
Apple
Apple
Mango

More Related Content

Similar to need this program in java please and thanks!NOTICE There are NO s.pdf

Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
rozakashif85
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
maheshkumar12354
 
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
 
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdfDividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
tesmondday29076
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
JamesPXNNewmanp
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
climatecontrolsv
 
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
mail931892
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
ezonesolutions
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
kingsandqueens3
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
arjuntelecom26
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
callawaycorb73779
 
project2.classpathproject2.project project2 .docx
project2.classpathproject2.project  project2 .docxproject2.classpathproject2.project  project2 .docx
project2.classpathproject2.project project2 .docx
briancrawford30935
 
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdfLab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
QalandarBux2
 

Similar to need this program in java please and thanks!NOTICE There are NO s.pdf (20)

Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
 
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
 
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdfDividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
 
3 j unit
3 j unit3 j unit
3 j unit
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
 
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
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
project2.classpathproject2.project project2 .docx
project2.classpathproject2.project  project2 .docxproject2.classpathproject2.project  project2 .docx
project2.classpathproject2.project project2 .docx
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdfLab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
 

More from arshin9

Discuss the impact that the tonnage of sulfur or sulfuric acid recov.pdf
Discuss the impact that the tonnage of sulfur or sulfuric acid recov.pdfDiscuss the impact that the tonnage of sulfur or sulfuric acid recov.pdf
Discuss the impact that the tonnage of sulfur or sulfuric acid recov.pdf
arshin9
 
You have decided to go to graduate school for Molecular Biology (yay!.pdf
You have decided to go to graduate school for Molecular Biology (yay!.pdfYou have decided to go to graduate school for Molecular Biology (yay!.pdf
You have decided to go to graduate school for Molecular Biology (yay!.pdf
arshin9
 
Write a java program to randomly generate the following sets of data.pdf
Write a java program to randomly generate the following sets of data.pdfWrite a java program to randomly generate the following sets of data.pdf
Write a java program to randomly generate the following sets of data.pdf
arshin9
 
What is the between facial action unit and facial landmark differenc.pdf
What is the between facial action unit and facial landmark differenc.pdfWhat is the between facial action unit and facial landmark differenc.pdf
What is the between facial action unit and facial landmark differenc.pdf
arshin9
 
Significance of Discoveries in Genetics and DNA Our understandin.pdf
Significance of Discoveries in Genetics and DNA Our understandin.pdfSignificance of Discoveries in Genetics and DNA Our understandin.pdf
Significance of Discoveries in Genetics and DNA Our understandin.pdf
arshin9
 

More from arshin9 (20)

Bats rely on sound localization to be able to fly during the night. O.pdf
Bats rely on sound localization to be able to fly during the night. O.pdfBats rely on sound localization to be able to fly during the night. O.pdf
Bats rely on sound localization to be able to fly during the night. O.pdf
 
A layer of dirt must be spread over a circular area 13.5 feet in dia.pdf
A layer of dirt must be spread over a circular area 13.5 feet in dia.pdfA layer of dirt must be spread over a circular area 13.5 feet in dia.pdf
A layer of dirt must be spread over a circular area 13.5 feet in dia.pdf
 
Discuss the impact that the tonnage of sulfur or sulfuric acid recov.pdf
Discuss the impact that the tonnage of sulfur or sulfuric acid recov.pdfDiscuss the impact that the tonnage of sulfur or sulfuric acid recov.pdf
Discuss the impact that the tonnage of sulfur or sulfuric acid recov.pdf
 
You have decided to go to graduate school for Molecular Biology (yay!.pdf
You have decided to go to graduate school for Molecular Biology (yay!.pdfYou have decided to go to graduate school for Molecular Biology (yay!.pdf
You have decided to go to graduate school for Molecular Biology (yay!.pdf
 
write the HTML to associate a web page with an external style sheet .pdf
write the HTML to associate a web page with an external style sheet .pdfwrite the HTML to associate a web page with an external style sheet .pdf
write the HTML to associate a web page with an external style sheet .pdf
 
Why was any carbon-containing molecule originally called organic.pdf
Why was any carbon-containing molecule originally called organic.pdfWhy was any carbon-containing molecule originally called organic.pdf
Why was any carbon-containing molecule originally called organic.pdf
 
Which of the following is true about indexes and index design a. in.pdf
Which of the following is true about indexes and index design  a. in.pdfWhich of the following is true about indexes and index design  a. in.pdf
Which of the following is true about indexes and index design a. in.pdf
 
Write a java program to randomly generate the following sets of data.pdf
Write a java program to randomly generate the following sets of data.pdfWrite a java program to randomly generate the following sets of data.pdf
Write a java program to randomly generate the following sets of data.pdf
 
What kind of organisms likely perished due to the increase of oxygen .pdf
What kind of organisms likely perished due to the increase of oxygen .pdfWhat kind of organisms likely perished due to the increase of oxygen .pdf
What kind of organisms likely perished due to the increase of oxygen .pdf
 
what is the HTTP protocol used for What are its major parts.pdf
what is the HTTP protocol used for What are its major parts.pdfwhat is the HTTP protocol used for What are its major parts.pdf
what is the HTTP protocol used for What are its major parts.pdf
 
What is the between facial action unit and facial landmark differenc.pdf
What is the between facial action unit and facial landmark differenc.pdfWhat is the between facial action unit and facial landmark differenc.pdf
What is the between facial action unit and facial landmark differenc.pdf
 
What are contemporary management challenges and opportunitiesSo.pdf
What are contemporary management challenges and opportunitiesSo.pdfWhat are contemporary management challenges and opportunitiesSo.pdf
What are contemporary management challenges and opportunitiesSo.pdf
 
Valinomycin is a potassium ionophore. What would be its effect on in.pdf
Valinomycin is a potassium ionophore. What would be its effect on in.pdfValinomycin is a potassium ionophore. What would be its effect on in.pdf
Valinomycin is a potassium ionophore. What would be its effect on in.pdf
 
The retrovirus genome is made of the nucleic acid before the virus be.pdf
The retrovirus genome is made of the nucleic acid before the virus be.pdfThe retrovirus genome is made of the nucleic acid before the virus be.pdf
The retrovirus genome is made of the nucleic acid before the virus be.pdf
 
the probability that it is raining is .25. the orbability that it is.pdf
the probability that it is raining is .25. the orbability that it is.pdfthe probability that it is raining is .25. the orbability that it is.pdf
the probability that it is raining is .25. the orbability that it is.pdf
 
2)In presentation software, you can use a(n) ____ to add movement to.pdf
2)In presentation software, you can use a(n) ____ to add movement to.pdf2)In presentation software, you can use a(n) ____ to add movement to.pdf
2)In presentation software, you can use a(n) ____ to add movement to.pdf
 
Significance of Discoveries in Genetics and DNA Our understandin.pdf
Significance of Discoveries in Genetics and DNA Our understandin.pdfSignificance of Discoveries in Genetics and DNA Our understandin.pdf
Significance of Discoveries in Genetics and DNA Our understandin.pdf
 
Scope is much less complicated if functions cannot contain other func.pdf
Scope is much less complicated if functions cannot contain other func.pdfScope is much less complicated if functions cannot contain other func.pdf
Scope is much less complicated if functions cannot contain other func.pdf
 
Refer to the drawings in Figure 13.2 of a single pair of homologous c.pdf
Refer to the drawings in Figure 13.2 of a single pair of homologous c.pdfRefer to the drawings in Figure 13.2 of a single pair of homologous c.pdf
Refer to the drawings in Figure 13.2 of a single pair of homologous c.pdf
 
Prions are viruses that cause proteins to misfold. Select one True.pdf
Prions are viruses that cause proteins to misfold.  Select one  True.pdfPrions are viruses that cause proteins to misfold.  Select one  True.pdf
Prions are viruses that cause proteins to misfold. Select one True.pdf
 

Recently uploaded

Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
cupulin
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 

need this program in java please and thanks!NOTICE There are NO s.pdf

  • 1. need this program in java please and thanks! NOTICE: There are NO static variables allowed in this lab. The only class that a static method is allowed is in the TestDriver class. The only static method that you actually really need is main. The purpose of this lab is to give you an opportunity to create your own linked list data structure and implement all the methods specified below to do list operations. The following specifies the linked list class which you must implement. Only implement the methods listed below. Do NOT add any additional member variables. class OrderedLinkedList { private class Node { // NOTE: The member variables are public so the methods // of the OrderedLinkedList class have direct access to them // NO setters and getters are needed – more efficient access. public String payload; public int keyValue; public Node next; // Explicit value constructor for the Node class public Node(String payload, int value) { …. } } private Node first; // This is the only member variable allowed. // You can NOT add any other member variables!!! public OrderedLinkedList ( ) { … } // default constructor public boolean empty( ) { … } // returns true if list is empty public String getFirst( ) throws Exception { … } // The first node is removed from the list and its payload is returned. // An exception with a meaningful error message is thrown if the list is empty. public String getLast( ) throws Exception { … } // The last node is removed from the list and its payload is returned. // An exception with a meaningful error message is thrown if the list is empty. public void insert(String payload, int key) throws Exception { … } // The insert method creates a new node, puts the input parameter values // into the new node, and then inserts the node into the list in sorted order // based on the keyValue. For example, if a list has 3 nodes with key values // of 5, 10, and 15, insertion of a new node which has a key value of 12 would // require that the new node was inserted after the node with key value of 10. // If the key being inserted is already in the list, throw an Exception with a // meaningful error string. Make sure that you test all possible cases for insertion. public void remove(int key) throws Exception { … } // Traverse the list, keeping track of where the precedessor for each node // is located. When the value is found in some node in the list, make the // predecessor node bypass the node which holds the value. If the key value // is not found, throw an Exception that indicates the error has occurred. public int listCount( ) { … } // Returns the number of nodes in the list. public String getValue(int key) throws Exception { … } // Traverse the list until you locate the requested key value. Return the // payload from the node which has the requested key value. If the key value // is not found, throw an Exception that indicates the error has occurred. public String toString( ) { … } // Override the toString method and create a string that contains the information // from all the nodes currently in the list. The string should be constructed such // that the data from each node will appear on a separate line. If the list is empty // the returned string should indicate that the list was empty. } Implement all the
  • 2. methods of this class and write a test program which thoroughly tests all of the methods in this class. Carefully consider each method and what meaningful test cases are needed to fully test each method. Make sure to identify each test case in your test driver class with a comment. You can write your test program any way you like, but your program must thoroughly exercise your class. Running the test program one time must result in the successful execution of every test case. It can be interactive with the user, or just have some specific hardwired test cases. Make sure that the output generated by your test program clearly indicates what each of your test cases is doing and what the results are. By running your test program one time, you should be convinced that every method of your class is running correctly under all circumstances. Your grade will partially be determined by how good of a job you do in testing your class. Make sure to test all the exception cases! Documentation You must provide complete documentation for the OrderedLinkedList class. Javadoc comments must be provided at the class level that include the author plus an overview of the purpose of the class. Javadoc comments must be provided for each method of the OrderedLinkedList class. The method level comments must include parameter explanations, return explanations, and exception explanations. Any preconditions should be explained with the parameters and exceptions, and postconditions should be explained with the return. You must generate the Javadoc documentation from your comments. You do this by clicking on Run in the NetBeans menu bar. Then click on Generate Javadoc. An HTML page will appear that contains all the comments extracted from the classes in your project. There should be no errors when running the Javadoc tool. Development Strategy Setup your project with the OrderedLinkedList class with all the methods specified containing no code so that the class compiles initially. You will need dummy return statements in some of the methods to get things to compile. Set up your test driver program to create an OrderedLinkedList object. Work on the insert method first followed by the toString method. Once you get those two methods written, you can start adding test cases to your test program to add items to the list and then use the toString method to return the content of the list to be displayed by your test program. Debug and test these methods first before moving on to the other methods. Once these methods are working, then implement and test one OrderedLinkedList class method at a time. Solution This is the program package LinkedList; import java.sql.SQLException; /** OrderedLinkedList class is for implementing linked list
  • 3. Basic functions such as getFirstNode, remove, insert are implemented. */ public class OrderedLinkedList { /** The Node class which contains a payload , a key and a next. next will hold the next node in the linked list */ private class Node{ public String payload; public int keyvalue; public Node next; /** * default constructor for the Node class * @param payload - contains the string value * @param keyvalue - integer value which represents a key */ public Node(String payload, int keyvalue) { this.payload = payload; this.keyvalue = keyvalue; } } private Node first; public OrderedLinkedList() { } /** * checks whether the list is empty * @return true or false indicating whether the list is empty */ public boolean empty() { boolean isEmpty = false;
  • 4. if(first == null) { isEmpty = true; } return isEmpty; } /** * find the first element in the list * @throws throws an exception if the list doesnt contain elements * @return return the payload for the first node */ public String getFirst( ) throws Exception{ String Mypayload = ""; try{ Mypayload = first.payload; } catch (Exception e) { // TODO: handle exception System.out.println("The list is empty."); } return Mypayload; } /** * find the last element in the list * @throws throws an exception if the list doesnt contain elements * @return return the payload for the last node */ public String getLast( ) throws Exception { String mypayload = ""; Node nodes = first; while(nodes.next != null) {
  • 5. nodes = nodes.next; } try{ mypayload = nodes.payload; }catch(Exception e) { System.out.println("List is empty"); } return mypayload; } /** * inserts element in the list by arranging the keys in ascending order * @param payload - the string to be inserted in the node * @param key - a unique key value * @throws throws an exception if the list doesnt contain elements */ public void insert(String payload, int key) throws Exception{ if(first == null) { first = new Node(payload, key); first.next = null; } else { while(first.next != null) { if(first.keyvalue > key) { Node Currentnode = first; Currentnode.keyvalue = key; Currentnode.payload = payload; Currentnode.next = first; } else {
  • 6. first = first.next; } } Node node = new Node(payload, key); first.next = node; } } /** * removes an element from the list * @throws throws an exception if the list doesnt contain elements * @param key - the unique key to be searched */ public void remove(int key) throws Exception { while(first.next!=null) { if(first.keyvalue == key) { Node nextNode = first.next; first.keyvalue = nextNode.keyvalue; first.payload = nextNode.payload; first.next = nextNode.next; } else { first = first.next; } } } /** * finds the total size of the list * @return integer - count of nodes in the list */ public int listCount( ) { int count = 0; if(!empty())
  • 7. { while(first.next != null) { count++; first = first.next; } } return count; } /** * finds the value of the key by traversing through the list * @throws throws an exception if the list doesnt contain elements * @return string - payload of the key */ public String getValue(int key) throws Exception { String value = ""; while(first.next!=null) { if(first.keyvalue == key) { try{ value = first.payload; } catch(Exception e) { System.out.println("Try again."); } } else { first = first.next; } } return value; }
  • 8. /** * displays the value of the payloads by traversing through the list * @return string - payload of the key */ public String toString( ) { String values = ""; while(first.next != null) { values = values + first.payload + " "; first = first.next; } return values; } } This is the main class package LinkedList; public class TestDriver { public static void main(String[] args) throws Exception { OrderedLinkedList list = new OrderedLinkedList(); list.insert("Apple", 2); list.getFirst(); list.getLast(); list.insert("Mango", 1); list.getValue(2); } } Output: Apple Apple Mango