Answered step by step
Verified Expert Solution
Question
1 Approved Answer
LinkedStringListTester Class Code: ContigousStringListTester Class Code: Description Implement the following String List ADT: A String List is a list (sequence) of strings with the following
LinkedStringListTester Class Code:
ContigousStringListTester Class Code:
Description Implement the following String List ADT: 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 is Empty() method that returns true if the list is empty. Otherwise, it returns false. 3. A boolean ishulll) method that returns true if the list is full. Otherwise, it retums false. 4. An int size () method that returns the number of elements (strings) in the list. 5. Avoid clearl) method that sets the list to be empty. A void insert 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 newStrat 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 newStr will be appended to the end of the list. If the position value is, for example, 0, then newStr 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 remove(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). 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 Buntime Exception if 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. A void replace String newStr, 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. 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 learned 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. 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 internal 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 CentaurusStringListTeater and Linkedsting Tester 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; 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 BuntimeException "Invalid position!"); The remove, retrieve, and replace methods should have a similar implementation as follows: if (position = count) throw new Buntime Exception/"Invalid position!"); 4. Note that for the linked implementation, we can assume that it will never be full. Therefore, the implementation of the issulll) method of the LinkedStringList class should always return false. PAGE 1 PAGE 2 if(!l.:Full) { System.out.println("The list is not full) LinkedStricelist Tester Class Code: public class LinkedStrivelit Tester { public static void main(String[] args) { LinkedStrivelit lsl = new LinkedStringListO: else System.out.println("The method is all System.exit(0); does not return correct result."): if (um) { System.out.println("Currently, the list is empty."); if (s ize == 1) { System.out.println("The length of the list is 1.'); else { System.out.println("The method is Empty does not return correct result."); Saten.exit(o): else System.out.println("The method size does not retum correct result."); System.exit(0); if (!l.:Full) { System.out.println("The list is not full."); System.out.printin: System.out.println("Inserting string "cc" at position 1...); else { System.out.println("The method is all does not retum correct result."); System.exit(0); Linger("cc", 1); System.out.println("String "ccc" inserted at position 1."); } catch (RoontimeException e) { System.out.println(e): System.out.println("The method insert does not work properly."); System.exit(0); if (15.si 0 == 0) { System.out.println("The length of the list is 0."); else { System.out.println("The method size does not retum correct result."); System.exit(0); if (!lli:Empo) System.out.println("Currently, the list is not empty'); System.out.printino: System.out.println("Inserting string "aaa" at position 0..."); else { System.out.println("The method is empty does not return correct result."); System.exit(0); Linger"23".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."); Syatenu.exit(0); if (!lalisFull) { System.out.println("The list is not full."); else { System.out.println("The method is ullo does not return correct result."): Statem.exit(0); if (!impo) System.out.println("Currently, the list is not empty'); if (Islasize == 2) { System.out.println("The length of the list is 2."); else { System.out.println("The method is Empty does not retum correct result."): Svatem.exit(0); else { System.out.println("The method size does not retur correct result."); Swaters.exit(0); PAGE 3 PAGE 4 System.out.printino else 1 System.out.println("The method is empty System.exit(0); does not return correct result."): System.out.println("Inserting string 'ddd at position 10..."); Lolitsert "dd. 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 (!l.:Full) { System.out.println("The list is not full"); else System.out.println("The method is Full System.exit(0); does not return correct result."): if (!lali Empt) { System.out.println("Currently, the list is not empty": if (Islasize == 3) { System.out.println("The length of the list is 3."); else { System.out.println("The method is empty does not retur correct result."); System.exit(0); else { System.out.println("The method size does not retur correct result."); System.exit(0); System.out.printino: if(!lli:fu10) { System.out.println("The list is not full."); System.out.println("Retrieving the string at position 0...'); else { System.out.println("The method is all does not retum correct result."): System.exit(0); if (1) retrieve().equals("aaa")) { System.out.println("String "224"retrieved from position 0."); } catch (RuntimeException e) { System.out.println(e). System.out.println("The method retrieve does not retum correct result."); System.exit(0); if (s ize == 2) { System.out.println("The length of the list is 2."); else { System.out.println("The method size does not retum correct result."): System.exit(0); System.out.printino: System.out.println("Retrieving the string at position 1...'); System.out.printin: System.out.println("Inserting string "bbh at position 1..."): if (retrieve().equals("bbb")) { System.out.println("String "bbb" retrieved from position 1."): Lalinsert "bbb". 1); System.out.println("String "bbh' inserted at position 1."); } catch (Runtime Exception e) { System.out.println(e) System.out.println("The method insert does not work properly."); Statem.exit(0); } catch (RuntimeException e) { System.out.println(e). System.out.println("The method retrieve does not retum correct result."); System.exit(0); System.out.printino: if (llisEmpt) { System.out.println("Currently, the list is not empty'); System.out.println("Retrieving the string at position 2...'); if (lal retrieve(2).equals("cc")) { System.out.println("String "cc" retrieved from position 2."); PAGE 5 PAGE 6 } catch (RuantimeException e) { System.out.println(e). System.out.println("The method retrieve does not retum correct result."); System.exit(0); Lemove(l): } catch (RuntimeException e) { System.out.println(e): System.out.println("The method remove does not work properly: "); System.exit(0); System.out.printino: if (!lalui: Empt:0) { System.out.println("Currently, the list is not empty'); System.out.println("Retrieving the string at position 10..."); else { System.out.println("The method is empty System.exit(0); does not return correct result."): ljubetrieve(10): System.out.println("The method retrieve does not work properly."); Svatem.exit(0); } catch (RuntimeException e) { System.out.println(e). System.out.println("We cannot retrieve from position 10 since the list size is 3."): if(!11. Fu10) { System.out.println("The list is not full."); else System.out.println("The method is ullo does not return correct result."): System.exit(0); System.out.println(); System.out.println("Replacing the string at position with "000"..."): try { Ishteplace("000.0): if (1) retrieve().equals("000")) { System.out.println("String "oo" placed into position 0"); if (ISIZO == 2) { System.out.println("The length of the list is 2."); else { System.out.println("The method size does not retum correct result."); System.exit(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("Retrieving the string at position 0...); if ( retrieve().equals("000")) { System.out.println("String "000" retrieved from position 0."): System.out.printino: } catch (RuntimeException e) { System.out.println(e): System.out.println("The method remove does not work properly:"); System.exit(0); System.out.println("Replacing the string at position 10...'); try Leheplace("111', 10); System.out.println("The method replace does not work properly: "); System.exit(0); } catch (RuantimeException 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("Retrieving the string at position 1...): System.out.printin: if ( 1retrieve(1).equals("cc")) { System.out.println("String "cc" retrieved from position 1."); } catch (RuntimeException e) { System.out.println(e): System.out.println("The method remove does not work properly: "); try { System.exit(0); PAGE 7 System.out.println("Removing the string at position 10 ..."): laltemowe(10): System.out.println("The method remove does not work properly: "); System.exit(0); } catch (Runtime Exception e) { System.out.println(e): System.out.println("We cannot remove the string at position 10 since the list size is 2."); System.out.printin: System.out.println("Clearing the whole list...'); lldaro: if (IsEmpt) { System.out.println("Currently, the list is empty"): else { System.out.println("The method clear does not work properly: "); System.exit(0); PAGES if (!l.:Full) { System.out.println("The list is not full"); else System.out.println("The method clear does not work properly:"): System.exit(0); if (baliza0 == 0) { System.out.println("The length of the list is 0."); else System.out.println("The method clear does not work properly: "); Suatem.exit(0); public class Contiguous StringListJester { PAGE 1 System.exit(0); PAGE 2 public static void main(String[] args) { Contiguous StringList.csl. = new ContizuousStringListO: if (!csl.isFull) { System.out.println("The list is not full."); if (cslisEmpt) { System.out.println("Currently, the list is empty."); else { System.out.println("The method is Full does not retum correct result."); System.exit(0); else { System.out.println("The method isEmpts:0 does not return correct result."); System.exit(0); if (cslsize0 == 1) { System.out.println("The length of the list is 1."); if (!eslui Eulo) { System.out.println("The list is not full."); else { System.out.println("The method size does not return correct result."); System.exit(0); else { System.out.println("The method is Full does not retum correct result."); System.exit(0); System.out.println(); System.out.println("Inserting string "cccl" at position 1..."); if (cslsize0 == 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); cal insert("ccc", 1); System.out.println("String "cc" inserted at position 1."); } catch (Runtime Exception e) { System.out.println(e); System.out.println("The method insert does not work properly."); System.exit(0); System.out.println(); System.out.println("Inserting string "aaa" at position 0..."); if (!cslisEmpt:0) { System.out.println("Currently, the list is not empty"); sslinsert("aaa", 0); System.out.println("String "aaal" inserted at position 0."); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method insert does not work properly"); System.exit(0); else { System.out.println("The method isEmpts:0 does not return correct result."); System.exit(0); if (!csl isFull) { System.out.println("The list is not full."); if (!cslisEmpt:0) { System.out.println("Currently, the list is not empty"); else { System.out.println("The method isEulo does not return correct result."); System.exit(0); else { System.out.println("The method isEmpty does not return correct result."); PAGE 3 if (cslsize0 == 2) { System.out.println("The length of the list is 2."); csl.insert("bhb", 1); PAGE 4 System.out.println("String "bbbl" inserted at position 1."); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method insert does not work properly."); System.exit(0); else { System.out.println("The method size does not return correct result."); System.exit(0); System.out.println(; if (!cslisEmpt:0) { System.out.println("Currently, the list is not empty"); 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 (RuntimeFxception e) { System.out.println(e); System.out.println("String "ddd." cannot be inserted at position 10."); else { System.out.println("The method isEmpty does not return correct result."); System.exit(0); if (csl.isFullO) { System.out.println("The list is full."); if (!csl.isEmpt:0) { System.out.println("Currently, the list is not empty."); else { System.out.println("The method is Full does not retum correct result."); System.exit(0); else { System.out.println("The method isEmpts:0 does not return correct result."); System.exit(0); if (!cslisFuld) { System.out.println("The list is not full."); 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); else { System.out.println("The method is Full does not retum correct result."); System.exit(0); System.out.println(); System.out.println("Retrieving the string at position 0..."); if (cslsize == 2) { System.out.println("The length of the list is 2."); if (eshtetrieve().equals("aaa")) { System.out.println("String "aaa" retrieved from position 0."); else { System.out.println("The method size does not return correct result."); System.exit(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(); System.out.println(); System.out.println("Inserting string "bbb." at position 1 ..."); System.out.println("Retrieving the string at position 1..."); PAGE 5 PAGE 6 System.out.println(e); System.out.println("The method replace) does not work properly."); System.exit(0); if (csljetrieve().equals("bbb")) { System.out.println("String "bbb" retrieved from position 1."); System.out.println(); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method retrieve does not return correct result."); System.exit(0); System.out.println("Replacing the string at position 10..."); try { cal.xeplace("111", 10); System.out.println("The method replace does not work properly."); System.exit(0); } catch (Runtime Fxception 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(); System.out.println("Retrieving the string at position 2 ..."); if (calretrieve(2).equals("cce")) { System.out.println("String "cce" retrieved from position 2."); System.out.println(); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method retrieve does not return correct result."); System.exit(0); System.out.println("Removing the string at position 1..."); try { calcenowe(1); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method remove does not work properly."); System.exit(0); System.out.println(); System.out.println("Retrieving the string at position 10 ...."); if (!cslisEmpt:0) { System.out.println("Currently, the list is not empty."); cal 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."); else { System.out.println("The method isEmpts:0 does not return correct result."); System.exit(0); System.out.println(); if (!csli Full) { System.out.println("The list is not full."); System.out.println("Replacing the string at position with "0001" ..."); try { cal replace("000", 0); if (eslutetrieve().equals("000")) { System.out.println("String "000" placed into position 0."); else { System.out.println("The method isFullo does not retum correct result."); System.exit(0); if (cslsize0 == 2) System.out.println("The length of the list is 2."); else { System.out.println("The method replace() does not work properly."); System.exit(0); } catch (Runtime Exception e) { else { System.out.println("The method size does not return correct result."); System.exit(0); PAGE 7 PAGE 3 if (!eslisFull) { System.out.println("The list is not full."); System.out.println("Retrieving the string at position 0..."); else 5 System.out.println("The method clear does not work properly."); System.exit(0); if (calcetrieve().equals("000")) { System.out.println("String "000" retrieved from position 0."); if (cslsize0 == 0) { System.out.println("The length of the list is 0."); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method remove does not work properly."); System.exit(0); else { System.out.println("The method clear does not work properly."); System.exit(0); System.out.println("Retrieving the string at position 1 ..."); try { if (calcetrieve(l).equals("cce")) { System.out.println("String "cce" 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(): System.out.println("Removing the string at position 10 ..."); calcemoxe(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(); System.out.println("Clearing the whole list ..."); csl.clearO; if (csl.isEmpt:0) { System.out.println("Currently, the list is empty:"); else { System.out.println("The method clear( does not work properly."); System.exit(0); Description Implement the following String List ADT: 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 is Empty() method that returns true if the list is empty. Otherwise, it returns false. 3. A boolean ishulll) method that returns true if the list is full. Otherwise, it retums false. 4. An int size () method that returns the number of elements (strings) in the list. 5. Avoid clearl) method that sets the list to be empty. A void insert 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 newStrat 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 newStr will be appended to the end of the list. If the position value is, for example, 0, then newStr 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 remove(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). 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 Buntime Exception if 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. A void replace String newStr, 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. 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 learned 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. 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 internal 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 CentaurusStringListTeater and Linkedsting Tester 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; 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 BuntimeException "Invalid position!"); The remove, retrieve, and replace methods should have a similar implementation as follows: if (position = count) throw new Buntime Exception/"Invalid position!"); 4. Note that for the linked implementation, we can assume that it will never be full. Therefore, the implementation of the issulll) method of the LinkedStringList class should always return false. PAGE 1 PAGE 2 if(!l.:Full) { System.out.println("The list is not full) LinkedStricelist Tester Class Code: public class LinkedStrivelit Tester { public static void main(String[] args) { LinkedStrivelit lsl = new LinkedStringListO: else System.out.println("The method is all System.exit(0); does not return correct result."): if (um) { System.out.println("Currently, the list is empty."); if (s ize == 1) { System.out.println("The length of the list is 1.'); else { System.out.println("The method is Empty does not return correct result."); Saten.exit(o): else System.out.println("The method size does not retum correct result."); System.exit(0); if (!l.:Full) { System.out.println("The list is not full."); System.out.printin: System.out.println("Inserting string "cc" at position 1...); else { System.out.println("The method is all does not retum correct result."); System.exit(0); Linger("cc", 1); System.out.println("String "ccc" inserted at position 1."); } catch (RoontimeException e) { System.out.println(e): System.out.println("The method insert does not work properly."); System.exit(0); if (15.si 0 == 0) { System.out.println("The length of the list is 0."); else { System.out.println("The method size does not retum correct result."); System.exit(0); if (!lli:Empo) System.out.println("Currently, the list is not empty'); System.out.printino: System.out.println("Inserting string "aaa" at position 0..."); else { System.out.println("The method is empty does not return correct result."); System.exit(0); Linger"23".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."); Syatenu.exit(0); if (!lalisFull) { System.out.println("The list is not full."); else { System.out.println("The method is ullo does not return correct result."): Statem.exit(0); if (!impo) System.out.println("Currently, the list is not empty'); if (Islasize == 2) { System.out.println("The length of the list is 2."); else { System.out.println("The method is Empty does not retum correct result."): Svatem.exit(0); else { System.out.println("The method size does not retur correct result."); Swaters.exit(0); PAGE 3 PAGE 4 System.out.printino else 1 System.out.println("The method is empty System.exit(0); does not return correct result."): System.out.println("Inserting string 'ddd at position 10..."); Lolitsert "dd. 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 (!l.:Full) { System.out.println("The list is not full"); else System.out.println("The method is Full System.exit(0); does not return correct result."): if (!lali Empt) { System.out.println("Currently, the list is not empty": if (Islasize == 3) { System.out.println("The length of the list is 3."); else { System.out.println("The method is empty does not retur correct result."); System.exit(0); else { System.out.println("The method size does not retur correct result."); System.exit(0); System.out.printino: if(!lli:fu10) { System.out.println("The list is not full."); System.out.println("Retrieving the string at position 0...'); else { System.out.println("The method is all does not retum correct result."): System.exit(0); if (1) retrieve().equals("aaa")) { System.out.println("String "224"retrieved from position 0."); } catch (RuntimeException e) { System.out.println(e). System.out.println("The method retrieve does not retum correct result."); System.exit(0); if (s ize == 2) { System.out.println("The length of the list is 2."); else { System.out.println("The method size does not retum correct result."): System.exit(0); System.out.printino: System.out.println("Retrieving the string at position 1...'); System.out.printin: System.out.println("Inserting string "bbh at position 1..."): if (retrieve().equals("bbb")) { System.out.println("String "bbb" retrieved from position 1."): Lalinsert "bbb". 1); System.out.println("String "bbh' inserted at position 1."); } catch (Runtime Exception e) { System.out.println(e) System.out.println("The method insert does not work properly."); Statem.exit(0); } catch (RuntimeException e) { System.out.println(e). System.out.println("The method retrieve does not retum correct result."); System.exit(0); System.out.printino: if (llisEmpt) { System.out.println("Currently, the list is not empty'); System.out.println("Retrieving the string at position 2...'); if (lal retrieve(2).equals("cc")) { System.out.println("String "cc" retrieved from position 2."); PAGE 5 PAGE 6 } catch (RuantimeException e) { System.out.println(e). System.out.println("The method retrieve does not retum correct result."); System.exit(0); Lemove(l): } catch (RuntimeException e) { System.out.println(e): System.out.println("The method remove does not work properly: "); System.exit(0); System.out.printino: if (!lalui: Empt:0) { System.out.println("Currently, the list is not empty'); System.out.println("Retrieving the string at position 10..."); else { System.out.println("The method is empty System.exit(0); does not return correct result."): ljubetrieve(10): System.out.println("The method retrieve does not work properly."); Svatem.exit(0); } catch (RuntimeException e) { System.out.println(e). System.out.println("We cannot retrieve from position 10 since the list size is 3."): if(!11. Fu10) { System.out.println("The list is not full."); else System.out.println("The method is ullo does not return correct result."): System.exit(0); System.out.println(); System.out.println("Replacing the string at position with "000"..."): try { Ishteplace("000.0): if (1) retrieve().equals("000")) { System.out.println("String "oo" placed into position 0"); if (ISIZO == 2) { System.out.println("The length of the list is 2."); else { System.out.println("The method size does not retum correct result."); System.exit(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("Retrieving the string at position 0...); if ( retrieve().equals("000")) { System.out.println("String "000" retrieved from position 0."): System.out.printino: } catch (RuntimeException e) { System.out.println(e): System.out.println("The method remove does not work properly:"); System.exit(0); System.out.println("Replacing the string at position 10...'); try Leheplace("111', 10); System.out.println("The method replace does not work properly: "); System.exit(0); } catch (RuantimeException 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("Retrieving the string at position 1...): System.out.printin: if ( 1retrieve(1).equals("cc")) { System.out.println("String "cc" retrieved from position 1."); } catch (RuntimeException e) { System.out.println(e): System.out.println("The method remove does not work properly: "); try { System.exit(0); PAGE 7 System.out.println("Removing the string at position 10 ..."): laltemowe(10): System.out.println("The method remove does not work properly: "); System.exit(0); } catch (Runtime Exception e) { System.out.println(e): System.out.println("We cannot remove the string at position 10 since the list size is 2."); System.out.printin: System.out.println("Clearing the whole list...'); lldaro: if (IsEmpt) { System.out.println("Currently, the list is empty"): else { System.out.println("The method clear does not work properly: "); System.exit(0); PAGES if (!l.:Full) { System.out.println("The list is not full"); else System.out.println("The method clear does not work properly:"): System.exit(0); if (baliza0 == 0) { System.out.println("The length of the list is 0."); else System.out.println("The method clear does not work properly: "); Suatem.exit(0); public class Contiguous StringListJester { PAGE 1 System.exit(0); PAGE 2 public static void main(String[] args) { Contiguous StringList.csl. = new ContizuousStringListO: if (!csl.isFull) { System.out.println("The list is not full."); if (cslisEmpt) { System.out.println("Currently, the list is empty."); else { System.out.println("The method is Full does not retum correct result."); System.exit(0); else { System.out.println("The method isEmpts:0 does not return correct result."); System.exit(0); if (cslsize0 == 1) { System.out.println("The length of the list is 1."); if (!eslui Eulo) { System.out.println("The list is not full."); else { System.out.println("The method size does not return correct result."); System.exit(0); else { System.out.println("The method is Full does not retum correct result."); System.exit(0); System.out.println(); System.out.println("Inserting string "cccl" at position 1..."); if (cslsize0 == 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); cal insert("ccc", 1); System.out.println("String "cc" inserted at position 1."); } catch (Runtime Exception e) { System.out.println(e); System.out.println("The method insert does not work properly."); System.exit(0); System.out.println(); System.out.println("Inserting string "aaa" at position 0..."); if (!cslisEmpt:0) { System.out.println("Currently, the list is not empty"); sslinsert("aaa", 0); System.out.println("String "aaal" inserted at position 0."); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method insert does not work properly"); System.exit(0); else { System.out.println("The method isEmpts:0 does not return correct result."); System.exit(0); if (!csl isFull) { System.out.println("The list is not full."); if (!cslisEmpt:0) { System.out.println("Currently, the list is not empty"); else { System.out.println("The method isEulo does not return correct result."); System.exit(0); else { System.out.println("The method isEmpty does not return correct result."); PAGE 3 if (cslsize0 == 2) { System.out.println("The length of the list is 2."); csl.insert("bhb", 1); PAGE 4 System.out.println("String "bbbl" inserted at position 1."); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method insert does not work properly."); System.exit(0); else { System.out.println("The method size does not return correct result."); System.exit(0); System.out.println(; if (!cslisEmpt:0) { System.out.println("Currently, the list is not empty"); 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 (RuntimeFxception e) { System.out.println(e); System.out.println("String "ddd." cannot be inserted at position 10."); else { System.out.println("The method isEmpty does not return correct result."); System.exit(0); if (csl.isFullO) { System.out.println("The list is full."); if (!csl.isEmpt:0) { System.out.println("Currently, the list is not empty."); else { System.out.println("The method is Full does not retum correct result."); System.exit(0); else { System.out.println("The method isEmpts:0 does not return correct result."); System.exit(0); if (!cslisFuld) { System.out.println("The list is not full."); 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); else { System.out.println("The method is Full does not retum correct result."); System.exit(0); System.out.println(); System.out.println("Retrieving the string at position 0..."); if (cslsize == 2) { System.out.println("The length of the list is 2."); if (eshtetrieve().equals("aaa")) { System.out.println("String "aaa" retrieved from position 0."); else { System.out.println("The method size does not return correct result."); System.exit(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(); System.out.println(); System.out.println("Inserting string "bbb." at position 1 ..."); System.out.println("Retrieving the string at position 1..."); PAGE 5 PAGE 6 System.out.println(e); System.out.println("The method replace) does not work properly."); System.exit(0); if (csljetrieve().equals("bbb")) { System.out.println("String "bbb" retrieved from position 1."); System.out.println(); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method retrieve does not return correct result."); System.exit(0); System.out.println("Replacing the string at position 10..."); try { cal.xeplace("111", 10); System.out.println("The method replace does not work properly."); System.exit(0); } catch (Runtime Fxception 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(); System.out.println("Retrieving the string at position 2 ..."); if (calretrieve(2).equals("cce")) { System.out.println("String "cce" retrieved from position 2."); System.out.println(); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method retrieve does not return correct result."); System.exit(0); System.out.println("Removing the string at position 1..."); try { calcenowe(1); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method remove does not work properly."); System.exit(0); System.out.println(); System.out.println("Retrieving the string at position 10 ...."); if (!cslisEmpt:0) { System.out.println("Currently, the list is not empty."); cal 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."); else { System.out.println("The method isEmpts:0 does not return correct result."); System.exit(0); System.out.println(); if (!csli Full) { System.out.println("The list is not full."); System.out.println("Replacing the string at position with "0001" ..."); try { cal replace("000", 0); if (eslutetrieve().equals("000")) { System.out.println("String "000" placed into position 0."); else { System.out.println("The method isFullo does not retum correct result."); System.exit(0); if (cslsize0 == 2) System.out.println("The length of the list is 2."); else { System.out.println("The method replace() does not work properly."); System.exit(0); } catch (Runtime Exception e) { else { System.out.println("The method size does not return correct result."); System.exit(0); PAGE 7 PAGE 3 if (!eslisFull) { System.out.println("The list is not full."); System.out.println("Retrieving the string at position 0..."); else 5 System.out.println("The method clear does not work properly."); System.exit(0); if (calcetrieve().equals("000")) { System.out.println("String "000" retrieved from position 0."); if (cslsize0 == 0) { System.out.println("The length of the list is 0."); } catch (RuntimeException e) { System.out.println(e); System.out.println("The method remove does not work properly."); System.exit(0); else { System.out.println("The method clear does not work properly."); System.exit(0); System.out.println("Retrieving the string at position 1 ..."); try { if (calcetrieve(l).equals("cce")) { System.out.println("String "cce" 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(): System.out.println("Removing the string at position 10 ..."); calcemoxe(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(); System.out.println("Clearing the whole list ..."); csl.clearO; if (csl.isEmpt:0) { System.out.println("Currently, the list is empty:"); else { System.out.println("The method clear( does not work properly."); System.exit(0)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started