Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with this program please help, I've attached the driver, exception classes, interface and results image below. I need to write a class that

Need help with this program please help, I've attached the driver, exception classes, interface and results image below. I need to write a class that implements the interface. The requirements for the class are commented in the interface. Ive also attached an image of the project requirements below. if you can please leave comments so that I can understand it better.

1 package list; 3 public class SortedListDriver { 5 public static void displayList(SortedListInterface list) { 6 // Displays the size and content of the ADT SortedList list 7 // sortedSize() and sortedGet() are tested automatically 8 System.out.println("Size = " + list.sortedSize()); 9 for (int i = 0; i

5 public class ListIndexOutOfBoundsException extends IndexOutOfBoundsException { 6 7 public ListIndexOutOfBoundsException(String s) { 8 super(s); 9 } 10 11 } // end ListIndexOutOfBoundsException

5 public class ListException extends RuntimeException { 6 7 public ListException(String s) { 8 super(s); 9 } 11 } // end ListException

6 public interface SortedListInterface { 12 public boolean sortedIsEmpty(); 13 // Determines whether a sorted list is empty. 14 // Precondition: None. 15 // Postcondition: Returns true if the list is empty, 16 // otherwise returns false. 17 // Throws: None. 18 19 public int sortedSize(); 20 // Determines the length of a sorted list. 21 // Precondition: None. 22 // Postcondition: Returns the number of items that are 23 // currently in the list. 24 // Throws: None. 25 26 public void sortedAdd(String item) 27 throws ListException; 28 // Adds an item into its proper sorted position in a sorted list. 29 // Precondition: None. 30 // Postcondition: If insertion is successful, item is at its 31 // proper sorted position in the list, and other items are 32 // renumbered accordingly. 33 // Throws: ListException if item cannot be placed on 34 // the list (list full). 35 36 public String sortedGet(int index) throws ListIndexOutOfBoundsException; 37 // Retrieves a sorted list item by position. 38 // Precondition: index is the number of the item to be 39 // retrieved. 40 // Postcondition: If 0 size()-1. 44 45 public void sortedRemove(String item) throws ListException; 46 // Deletes item from a sorted list. 47 // Precondition: None. 48 // Postcondition: If 0

image text in transcribedimage text in transcribed

Objective This project is to reinforce the concept of ADT by the implementation of an ADT Sorted List. Description This project is to develop programs to deal with sorted lists of strings. The interface and a driver program are provided. The main task is the implementation of the interface. ADT Sorted List The operations of ADT Sorted List are specified in SortedListInterface.java. Your task is to implement the operations defined in the interface and the constructor. Reference-Based Implementation A linked list is used to store data in the sorted list. Development Requirements 1. You are NOT ALLOWED to modify the interface file and the exception files provided to you, except for adding package statement at the beginning as needed. 2. 3. 4. Encapsulation should be enforced. 5. Use a simple linked list with a head reference to the beginning of the list. 6. The Node class should have a string item and a Node next variables. 7. The constructor creates an empty list. 8. When an item is added, it needs to be added into the correct position to keep the list sorted. No sorting operation is allowed. 9. You may adapt the code of ADT List's reference-based implementation in the textbook for this project. 10. You are required to develop a private Node find(String item) method that locates a specified node in a linked list 1) The method is similar to the Node find(int index) method in the ADT List reference-based implementation in the textbook. 2) The find() method needs to be called and used by sortedAdd() and sortedRemove() to locate the node before which a node should be added or removed. 3) You may begin without a find() method and then extract the common code from add and remove to develop the method later. (This approach can be thought of as a "software refactoring" example.) 11. You are required to develop code to build your linked list from scratch and to manipulate references. 12. You are NOT ALLOWED to use Java's Collections, java.util.Linkedlist, or alike. 13. No array should be used in the implementation. Project2Result.txt *** Test case 1: Test sortedIsEmpty() List empty is true Size = 0 *** Test case 2: Test sortedAdd() *** Test case 2.1: Add first item List empty is false Size = 1 Item in position is: butter *** Test case 2.2: Add to end Size = 2 Item in position is: butter Item in position 1 is: milk *** Test case 2.3: Add to beginning Size = 3 Item in position is: apples Item in position 1 is: butter Item in position 2 is: milk *** Test case 2.4: Add more Size = 6 Item in position is: apples Item in position 1 is: butter Item in position 2 is: coffee Item in position 3 is: milk Item in position 4 is: oranges Item in position 5 is: peaches *** Test case 2.5: Add duplicate Size = 10 Item in position is: apples Item in position 1 is: apples Item in position 2 is: butter Item in position 3 is: coffee Item in position 4 is: milk Item in position 5 is: milk Item in position 6 is: milk Item in position 7 is: oranges Item in position 8 is: oranges Item in position 9 is: peaches *** Test case 3: Test sortedRemove() Size = 6 Item in position @ is: apples Item in position 1 is: butter Item in position 2 is: milk Item in position 3 is: milk Item in position 4 is: milk Item in position 5 is: oranges *** Test case 4: Test locateIndex() Index of eggs = -1 Index of oranges = 5 Index of milk = 2 Index of bananas = -1 Index of water = -1 Index of cheese = -1 *** Test case 5: Test exceptions *** Test case 5.1: Exception thrown by sortedGet() list.ListIndexOutOfBoundsException: ListIndexOutOfBoundsException on get 10 *** Test case 5.2: Exception thrown by sortedAdd() Size = 23 Item in position is: apples Item in position 1 is: butter Item in position 2 is: food item Item in position 3 is: food item1 Item in position 4 is: food item10 Item in position 5 is: food item11 Item in position 6 is: food item12 Item in position 7 is: food item13 Item in position 8 is: food item14 Item in position 9 is: food item15 Item in position 10 is: food item2 Item in position 11 is: food item3 Item in position 12 is: food item4 Item in position 13 is: food items Item in position 14 is: food item6 Item in position 15 is: food item7 Item in position 16 is: food item8 Item in position 17 is: food item9 Item in position 18 is: milk Item in position 19 is: milk Item in position 20 is: milk Item in position 21 is: oranges Item in position 22 is: oranges *** Test case 5.3: Exception thrown by sortedRemove() list. ListException: ListException on remove water list.ListException: ListException on remove earth list. ListException: ListException on remove fire list. ListException: ListException on remove air Size = 23 Item in position is: apples Item in position 1 is: butter Item in position 2 is: food item Item in position 3 is: food item1 Item in position 4 is: food item10 Item in position 5 is: food item11 Item in position 6 is: food item12 Item in position 7 is: food item13 Item in position 8 is: food item14 Item in position 9 is: food item15 Item in position 10 is: food item2 Item in position 11 is: food item3 Item in position 12 is: food item4 Item in position 13 is: food item5 Item in position 14 is: food item Item in position 15 is: food item 7 Item in position 16 is: food item8 Item in position 17 is: food item9 Item in position 18 is: milk Item in position 19 is: milk Item in position 20 is: milk Item in position 21 is: oranges Item in position 22 is: oranges *** Test case6: Test sortedRemoveAll() After remove all: Size = 0 Objective This project is to reinforce the concept of ADT by the implementation of an ADT Sorted List. Description This project is to develop programs to deal with sorted lists of strings. The interface and a driver program are provided. The main task is the implementation of the interface. ADT Sorted List The operations of ADT Sorted List are specified in SortedListInterface.java. Your task is to implement the operations defined in the interface and the constructor. Reference-Based Implementation A linked list is used to store data in the sorted list. Development Requirements 1. You are NOT ALLOWED to modify the interface file and the exception files provided to you, except for adding package statement at the beginning as needed. 2. 3. 4. Encapsulation should be enforced. 5. Use a simple linked list with a head reference to the beginning of the list. 6. The Node class should have a string item and a Node next variables. 7. The constructor creates an empty list. 8. When an item is added, it needs to be added into the correct position to keep the list sorted. No sorting operation is allowed. 9. You may adapt the code of ADT List's reference-based implementation in the textbook for this project. 10. You are required to develop a private Node find(String item) method that locates a specified node in a linked list 1) The method is similar to the Node find(int index) method in the ADT List reference-based implementation in the textbook. 2) The find() method needs to be called and used by sortedAdd() and sortedRemove() to locate the node before which a node should be added or removed. 3) You may begin without a find() method and then extract the common code from add and remove to develop the method later. (This approach can be thought of as a "software refactoring" example.) 11. You are required to develop code to build your linked list from scratch and to manipulate references. 12. You are NOT ALLOWED to use Java's Collections, java.util.Linkedlist, or alike. 13. No array should be used in the implementation. Project2Result.txt *** Test case 1: Test sortedIsEmpty() List empty is true Size = 0 *** Test case 2: Test sortedAdd() *** Test case 2.1: Add first item List empty is false Size = 1 Item in position is: butter *** Test case 2.2: Add to end Size = 2 Item in position is: butter Item in position 1 is: milk *** Test case 2.3: Add to beginning Size = 3 Item in position is: apples Item in position 1 is: butter Item in position 2 is: milk *** Test case 2.4: Add more Size = 6 Item in position is: apples Item in position 1 is: butter Item in position 2 is: coffee Item in position 3 is: milk Item in position 4 is: oranges Item in position 5 is: peaches *** Test case 2.5: Add duplicate Size = 10 Item in position is: apples Item in position 1 is: apples Item in position 2 is: butter Item in position 3 is: coffee Item in position 4 is: milk Item in position 5 is: milk Item in position 6 is: milk Item in position 7 is: oranges Item in position 8 is: oranges Item in position 9 is: peaches *** Test case 3: Test sortedRemove() Size = 6 Item in position @ is: apples Item in position 1 is: butter Item in position 2 is: milk Item in position 3 is: milk Item in position 4 is: milk Item in position 5 is: oranges *** Test case 4: Test locateIndex() Index of eggs = -1 Index of oranges = 5 Index of milk = 2 Index of bananas = -1 Index of water = -1 Index of cheese = -1 *** Test case 5: Test exceptions *** Test case 5.1: Exception thrown by sortedGet() list.ListIndexOutOfBoundsException: ListIndexOutOfBoundsException on get 10 *** Test case 5.2: Exception thrown by sortedAdd() Size = 23 Item in position is: apples Item in position 1 is: butter Item in position 2 is: food item Item in position 3 is: food item1 Item in position 4 is: food item10 Item in position 5 is: food item11 Item in position 6 is: food item12 Item in position 7 is: food item13 Item in position 8 is: food item14 Item in position 9 is: food item15 Item in position 10 is: food item2 Item in position 11 is: food item3 Item in position 12 is: food item4 Item in position 13 is: food items Item in position 14 is: food item6 Item in position 15 is: food item7 Item in position 16 is: food item8 Item in position 17 is: food item9 Item in position 18 is: milk Item in position 19 is: milk Item in position 20 is: milk Item in position 21 is: oranges Item in position 22 is: oranges *** Test case 5.3: Exception thrown by sortedRemove() list. ListException: ListException on remove water list.ListException: ListException on remove earth list. ListException: ListException on remove fire list. ListException: ListException on remove air Size = 23 Item in position is: apples Item in position 1 is: butter Item in position 2 is: food item Item in position 3 is: food item1 Item in position 4 is: food item10 Item in position 5 is: food item11 Item in position 6 is: food item12 Item in position 7 is: food item13 Item in position 8 is: food item14 Item in position 9 is: food item15 Item in position 10 is: food item2 Item in position 11 is: food item3 Item in position 12 is: food item4 Item in position 13 is: food item5 Item in position 14 is: food item Item in position 15 is: food item 7 Item in position 16 is: food item8 Item in position 17 is: food item9 Item in position 18 is: milk Item in position 19 is: milk Item in position 20 is: milk Item in position 21 is: oranges Item in position 22 is: oranges *** Test case6: Test sortedRemoveAll() After remove all: Size = 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

=+1 What would you do if you were the IHR manager?

Answered: 1 week ago