Question: Two separate classes called ContiguousStringListTester and LinkedStringListTester are provided to test the two classes that you create, respectively. The two tester classes will report an

 Two separate classes called ContiguousStringListTester and LinkedStringListTester are provided to test

Two separate classes called ContiguousStringListTester and LinkedStringListTester are provided to test the two classes that you create, respectively. The two tester classes will report an error message if they detect any error in your implementations /** * A program that tests the class ContiguousStringList */ public class ContiguousStringListTester { /** * main method: test the class ContiguousIntQueue */ public static void main(String[] args) { ContiguousStringList csl = new ContiguousStringList(); // Empty list if (csl.isEmpty()) { System.out.println("Currently, the list is empty."); } else { System.out.println("The method isEmpty() does not return correct result."); System.exit(0); } if (!csl.isFull()) { System.out.println("The list is not full."); } else { System.out.println("The method isFull() does not return correct result."); System.exit(0); } if (csl.size() == 0) { System.out.println("The length of the list is 0."); } else { System.out.println("The method size() does not return correct result."); System.exit(0); } System.out.println(); // inserting "aaa" at 0 System.out.println("Inserting string \"aaa\" at position 0 ..."); try { csl.insert("aaa", 0); System.out.println("String \"aaa\" inserted at position 0."); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method insert() does not work properly."); System.exit(0); } if (!csl.isEmpty()) { System.out.println("Currently, the list is not empty."); } else { System.out.println("The method isEmpty() does not return correct result."); System.exit(0); } if (!csl.isFull()) { System.out.println("The list is not full."); } else { System.out.println("The method isFull() does not return correct result."); System.exit(0); } if (csl.size() == 1) { System.out.println("The length of the list is 1."); } else { System.out.println("The method size() does not return correct result."); System.exit(0); } System.out.println(); // inserting "ccc" at 1 System.out.println("Inserting string \"ccc\" at position 1 ..."); try { csl.insert("ccc", 1); System.out.println("String \"ccc\" inserted at position 1."); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method insert() does not work properly."); System.exit(0); } if (!csl.isEmpty()) { System.out.println("Currently, the list is not empty."); } else { System.out.println("The method isEmpty() does not return correct result."); System.exit(0); } if (!csl.isFull()) { System.out.println("The list is not full."); } else { System.out.println("The method isFull() does not return correct result."); System.exit(0); } if (csl.size() == 2) { System.out.println("The length of the list is 2."); } else { System.out.println("The method size() does not return correct result."); System.exit(0); } System.out.println(); // inserting "ddd" at 10 System.out.println("Inserting string \"ddd\" at position 10 ..."); try { csl.insert("ddd", 10); System.out.println("The method insert() does not work properly."); System.exit(0); } catch (RuntimeException e) { System.out.println(e); System.out.println("String \"ddd\" cannot be inserted at position 10."); } if (!csl.isEmpty()) { System.out.println("Currently, the list is not empty."); } else { System.out.println("The method isEmpty() does not return correct result."); System.exit(0); } if (!csl.isFull()) { System.out.println("The list is not full."); } else { System.out.println("The method isFull() does not return correct result."); System.exit(0); } if (csl.size() == 2) { System.out.println("The length of the list is 2."); } else { System.out.println("The method size() does not return correct result."); System.exit(0); } System.out.println(); // inserting "bbb" at 1 System.out.println("Inserting string \"bbb\" at position 1 ..."); try { csl.insert("bbb", 1); System.out.println("String \"bbb\" inserted at position 1."); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method insert() does not work properly."); System.exit(0); } if (!csl.isEmpty()) { System.out.println("Currently, the list is not empty."); } else { System.out.println("The method isEmpty() does not return correct result."); System.exit(0); } if (csl.isFull()) { System.out.println("The list is full."); } else { System.out.println("The method isFull() does not return correct result."); System.exit(0); } if (csl.size() == 3) { System.out.println("The length of the list is 3."); } else { System.out.println("The method size() does not return correct result."); System.exit(0); } System.out.println(); // retrieving "aaa" System.out.println("Retrieving the string at position 0 ..."); try { if (csl.retrieve(0).equals("aaa")) { System.out.println("String \"aaa\" retrieved from position 0."); } } catch (RuntimeException e) { System.out.println(e); System.out.println("The method retrieve() does not return correct result."); System.exit(0); } System.out.println(); // retrieving "bbb" System.out.println("Retrieving the string at position 1 ..."); try { if (csl.retrieve(1).equals("bbb")) { System.out.println("String \"bbb\" retrieved from position 1."); } } catch (RuntimeException e) { System.out.println(e); System.out.println("The method retrieve() does not return correct result."); System.exit(0); } System.out.println(); // retrieving "ccc" System.out.println("Retrieving the string at position 2 ..."); try { if (csl.retrieve(2).equals("ccc")) { System.out.println("String \"ccc\" retrieved from position 2."); } } catch (RuntimeException e) { System.out.println(e); System.out.println("The method retrieve() does not return correct result."); System.exit(0); } System.out.println(); // retrieving from position 10 System.out.println("Retrieving the string at position 10 ..."); try { csl.retrieve(10); System.out.println("The method retrieve() does not work properly."); System.exit(0); } catch (RuntimeException e) { System.out.println(e); System.out.println("We cannot retrieve from position 10 since the list size is 3."); } System.out.println(); // replacing "aaa" with "000" System.out.println("Replacing the string at position 0 with \"000\" ..."); try { csl.replace("000", 0); if (csl.retrieve(0).equals("000")) { System.out.println("String \"000\" placed into position 0."); } else { System.out.println("The method replace() does not work properly."); System.exit(0); } } catch (RuntimeException e) { System.out.println(e); System.out.println("The method replace() does not work properly."); System.exit(0); } System.out.println(); // replacing at position 10 System.out.println("Replacing the string at position 10 ..."); try { csl.replace("111", 10); System.out.println("The method replace() does not work properly."); System.exit(0); } catch (RuntimeException e) { System.out.println(e); System.out.println("We cannot replace the string at position 10 since the list size is 3."); } System.out.println(); // removing "bbb" at position 1 System.out.println("Removing the string at position 1 ..."); try { csl.remove(1); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method remove() does not work properly."); System.exit(0); } if (!csl.isEmpty()) { System.out.println("Currently, the list is not empty."); } else { System.out.println("The method isEmpty() does not return correct result."); System.exit(0); } if (!csl.isFull()) { System.out.println("The list is not full."); } else { System.out.println("The method isFull() does not return correct result."); System.exit(0); } if (csl.size() == 2) { System.out.println("The length of the list is 2."); } else { System.out.println("The method size() does not return correct result."); System.exit(0); } // retrieving "000" System.out.println("Retrieving the string at position 0 ..."); try { if (csl.retrieve(0).equals("000")) { System.out.println("String \"000\" retrieved from position 0."); } } catch (RuntimeException e) { System.out.println(e); System.out.println("The method remove() does not work properly."); System.exit(0); } // retrieving "ccc" System.out.println("Retrieving the string at position 1 ..."); try { if (csl.retrieve(1).equals("ccc")) { System.out.println("String \"ccc\" retrieved from position 1."); } } catch (RuntimeException e) { System.out.println(e); System.out.println("The method remove() does not work properly."); System.exit(0); } System.out.println(); // removing at position 10 System.out.println("Removing the string at position 10 ..."); try { csl.remove(10); System.out.println("The method remove() does not work properly."); System.exit(0); } catch (RuntimeException e) { System.out.println(e); System.out.println("We cannot remove the string at position 10 since the list size is 2."); } System.out.println(); // inserting "aaa" at 0 System.out.println("Inserting string \"aaa\" at position 0 ..."); try { csl.insert("aaa", 0); System.out.println("String \"aaa\" inserted at position 0."); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method insert() does not work properly."); System.exit(0); } // retrieving "aaa" System.out.println("Retrieving the string at position 0 ..."); try { if (csl.retrieve(0).equals("aaa")) { System.out.println("String \"aaa\" retrieved from position 0."); } } catch (RuntimeException e) { System.out.println(e); System.out.println("The method retrieve() does not return correct result."); System.exit(0); } System.out.println(); // clearing the list System.out.println("Clearing the whole list ..."); csl.clear(); if (csl.isEmpty()) { System.out.println("Currently, the list is empty."); } else { System.out.println("The method clear() does not work properly."); System.exit(0); } if (!csl.isFull()) { System.out.println("The list is not full."); } else { System.out.println("The method clear() does not work properly."); System.exit(0); } if (csl.size() == 0) { System.out.println("The length of the list is 0."); } else { System.out.println("The method clear() does not work properly."); System.exit(0); } } }

CMSC 3103 Programming Assignment 2 Due: The due date is listed in the D2L calendar Total points: 100 Note that certain methods (e.g., insert) in the ADT throw RuntimeException directly. This should NOT happen in a real implementation. You almost always need to implement your own exception types, which can be a subclass of Exception or RuntimeException depending on the situation. Since we have not covered how to define a new exception type, we use RuntimeException here. In this programming assignment, you are allowed to use RuntimeException. Once we have leamed how to defined user exception types, you should not use RuntimeException directly in your solution anymore since the thrown exception should give more information about the error to the user. Description Implement the following String List ADT: You are required to implement TWO classes based on the String List ADT. The first class, named ContiguousStringList, should utilize a contiguous implementation, that is, the intemal representation of the sequence of strings should be an array of strings. The second class, named LinkedStringList, should use a linked data structure to represent the sequence of strings. Two separate classes called ContigueusStringListJester and LinkedStringlast Testek are provided to test the two classes that you create, respectively. The two tester classes will report an error message if they detect any error in your implementations. Sample programs in Java are provided as a reference. They are integer queues using contiguous and linked implementations, respectively. List implementations in C++ are also provided as a reference. Hints 1. You need to specify a default array size in the contiguous implementation since you need to create an array of strings for the list. For the purpose of this assignment, a default array size of 3 should be used. Usually, the default array size can be specified within the class declaration as a private, static and final value as follows: private static final int DEFAULT_ARRAY_SIZE = 3; A String List is a list (sequence) of strings with the following methods: 1. A constructor that initializes the list to be empty. 2. A boolean isEmpts ) method that returns true if the list is empty. Otherwise, it returns false. 3. A boolean is full method that returns true if the list is full. Otherwise, it returns false. 4. An int size() method that returns the number of elements (strings) in the list. 5. Avoid clear!) method that sets the list to be empty. 6. Avoid insert L.String newStr, int position) method that throws a RuntimeException, if the position value is not valid in the list (i.e., beyond the current size of the list or being negative). It also throws a RuntimeException, if the list is full. Otherwise, it inserts newStr at position in the list. If position equals the current number of strings in the list, then newStr is simply appended to the list. Otherwise, newStr is inserted at position in the list, and the original string at position and the subsequent strings in the list are moved to the next position in the list. Note that position starts from 0. If, for example, the current number of strings in the list is 3, then a valid position value should be between 0 and 3, inclusively. In this example, if the position value is 3, then pewStr will be appended to the end of the list. If the position value is, for example, 0, then newster will be inserted at the beginning of the list while the original strings at positions 0, 1 and 2 are moved to positions 1, 2 and 3, respectively. In either case, the number of strings in the list becomes 4 after the insertion A void remaste lint position) method that throws a RuntimeException, if the position value is not valid in the list (i.e., beyond the last position of the list or being negative). It also throws a RuntimeException, if the list is empty. Otherwise, it removes the string at position in the list. After the removal, strings that follow the deleted string at position in the list, if any, are moved backward by one position Note that position starts from 0. If, for example, the current number of strings in the list is 3, then a valid position value should be between 0 and 2, inclusively. In this example, if the position value is 2, then the last string in the list will be simply removed. If the position value is, for example, 0, then the string at position 0 will be removed and the original strings at positions 1 and 2 will be moved to positions 0 and 1, respectively. In either case, the number of strings in the list is reduced to 2 after the removal. 8. A String retrieve(int position) method that throws a Buns e ntent the position value is not valid in the list (i.e., beyond the last position of the list or being negative). Otherwise, it returns the string at position in the list. 9. A void replace(String new Str, int position) method that throws a RuntimeException, if the position value is not valid in the list (i.e., beyond the last position of the list or being negative). Otherwise, it replaces the string at position with newStr. 2. You need to declare an instance variable count in the contiguous implementation to indicate the current number of strings in the array. For efficiency purpose, it is also desirable to declare such an instance variable in the linked implementation. 3. The insert method in both classes should check the validity of the position argument. A RuntimeException should be thrown if the position is invalid. For example, you can use if (position count) throw new BuntimeExceptiand"Invalid position!"); The remove, retrieve, and replace methods should have a similar implementation as follows: if (position = count) throw new RuntimeException "Invalid position!"); 4. Note that for the linked implementation, we can assume that it will never be full. Therefore, the implementation of the ishull) method of the LinkedStringList class should always return false. Submission CMSC 3103 Programming Assignment 2 Due: The due date is listed in the D2L calendar Total points: 100 Note that certain methods (e.g., insert) in the ADT throw RuntimeException directly. This should NOT happen in a real implementation. You almost always need to implement your own exception types, which can be a subclass of Exception or RuntimeException depending on the situation. Since we have not covered how to define a new exception type, we use RuntimeException here. In this programming assignment, you are allowed to use RuntimeException. Once we have leamed how to defined user exception types, you should not use RuntimeException directly in your solution anymore since the thrown exception should give more information about the error to the user. Description Implement the following String List ADT: You are required to implement TWO classes based on the String List ADT. The first class, named ContiguousStringList, should utilize a contiguous implementation, that is, the intemal representation of the sequence of strings should be an array of strings. The second class, named LinkedStringList, should use a linked data structure to represent the sequence of strings. Two separate classes called ContigueusStringListJester and LinkedStringlast Testek are provided to test the two classes that you create, respectively. The two tester classes will report an error message if they detect any error in your implementations. Sample programs in Java are provided as a reference. They are integer queues using contiguous and linked implementations, respectively. List implementations in C++ are also provided as a reference. Hints 1. You need to specify a default array size in the contiguous implementation since you need to create an array of strings for the list. For the purpose of this assignment, a default array size of 3 should be used. Usually, the default array size can be specified within the class declaration as a private, static and final value as follows: private static final int DEFAULT_ARRAY_SIZE = 3; A String List is a list (sequence) of strings with the following methods: 1. A constructor that initializes the list to be empty. 2. A boolean isEmpts ) method that returns true if the list is empty. Otherwise, it returns false. 3. A boolean is full method that returns true if the list is full. Otherwise, it returns false. 4. An int size() method that returns the number of elements (strings) in the list. 5. Avoid clear!) method that sets the list to be empty. 6. Avoid insert L.String newStr, int position) method that throws a RuntimeException, if the position value is not valid in the list (i.e., beyond the current size of the list or being negative). It also throws a RuntimeException, if the list is full. Otherwise, it inserts newStr at position in the list. If position equals the current number of strings in the list, then newStr is simply appended to the list. Otherwise, newStr is inserted at position in the list, and the original string at position and the subsequent strings in the list are moved to the next position in the list. Note that position starts from 0. If, for example, the current number of strings in the list is 3, then a valid position value should be between 0 and 3, inclusively. In this example, if the position value is 3, then pewStr will be appended to the end of the list. If the position value is, for example, 0, then newster will be inserted at the beginning of the list while the original strings at positions 0, 1 and 2 are moved to positions 1, 2 and 3, respectively. In either case, the number of strings in the list becomes 4 after the insertion A void remaste lint position) method that throws a RuntimeException, if the position value is not valid in the list (i.e., beyond the last position of the list or being negative). It also throws a RuntimeException, if the list is empty. Otherwise, it removes the string at position in the list. After the removal, strings that follow the deleted string at position in the list, if any, are moved backward by one position Note that position starts from 0. If, for example, the current number of strings in the list is 3, then a valid position value should be between 0 and 2, inclusively. In this example, if the position value is 2, then the last string in the list will be simply removed. If the position value is, for example, 0, then the string at position 0 will be removed and the original strings at positions 1 and 2 will be moved to positions 0 and 1, respectively. In either case, the number of strings in the list is reduced to 2 after the removal. 8. A String retrieve(int position) method that throws a Buns e ntent the position value is not valid in the list (i.e., beyond the last position of the list or being negative). Otherwise, it returns the string at position in the list. 9. A void replace(String new Str, int position) method that throws a RuntimeException, if the position value is not valid in the list (i.e., beyond the last position of the list or being negative). Otherwise, it replaces the string at position with newStr. 2. You need to declare an instance variable count in the contiguous implementation to indicate the current number of strings in the array. For efficiency purpose, it is also desirable to declare such an instance variable in the linked implementation. 3. The insert method in both classes should check the validity of the position argument. A RuntimeException should be thrown if the position is invalid. For example, you can use if (position count) throw new BuntimeExceptiand"Invalid position!"); The remove, retrieve, and replace methods should have a similar implementation as follows: if (position = count) throw new RuntimeException "Invalid position!"); 4. Note that for the linked implementation, we can assume that it will never be full. Therefore, the implementation of the ishull) method of the LinkedStringList class should always return false. Submission

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!