DO NOT USE ANY WHILE (TRUE) CONSTRUCTS OR BREAK STATEMENTS TO HALT ANY LOOP PREM
ID: 3638532 • Letter: D
Question
DO NOT USE ANY WHILE (TRUE) CONSTRUCTS OR BREAK STATEMENTS TO HALT ANY LOOP PREMATURELY! (The author of the text uses these regularly, don’t use his code– modify it!)INTERFACE:
This object will be called an OrderedStringList. It’s purpose is to provide a means for storing String objects in sorted order, and allow convenient manipulation of the data. There are no public data elements. It implements the following methods:
OrderedStringList(int size)– constructor for the class, this initializes the internal array of Strings to have size elements, all empty.
public int size()– returns the number of elements currently in the list.
public int find(String s)– returns the index location of s if it is in the list, or -1 if it is not in the list.
public bool insert(String s)– adds s to the list in sorted order, returns true if successful, or false if there was not enough room allocated.
public bool delete(String s)– returns true if the value s was found and removed, returns false if the value was not found.
public bool deleteRange(String start, String stop)– deletes all strings within the range from strings start to stop, inclusive, and all in between. Returns true if any values were deleted, false if no strings were in the given range. *This method must use the above find and delete methods to achieve its functionality!
public void displayNoLF()– uses print to show the strings in order, without index numbers, and without newlines in between them.
public void display()– uses println to show the strings in order, with index numbers, spaced nicely in a vertical column.
public bool merge(OrderedStringList a, OrderedStringList b)– combines the contents of the two parameter lists into the list whose method was called, initializing its allocated size to twice the current content size of a + content size of b, so only the contents of a and b remain, and c is half-full. The proper way to call this would be:
OrderedStringList a = new OrderedStringList(size1);
OrderedStringList b = new OrderedStringList(size2);
OrderedStringList c = new OrderedStringList(anysize); //will be reallocated at merge
// then, after putting data into a and b....
if c.merge(a,b)) system.out.println(“Merge was successful.);
MAIN PROGRAM:
The main program must test every one of the methods of the OrderedStringList, in the order they are listed above, where possible, for easier grading and demonstrate that they work as specified. The programmer is to select the string data to be stored using seven string values in each OrderedStringList being demonstrated.
OUTPUTS:
The outputs for this program are meant to label and demonstrate clearly each tested method. The good quality output, format to be chosen by the programmer, must explain what is being done (e.g., “Adding these strings to ordered list #1: dog, cat, airplane”, then “Contents of ordered list #1:”, etc. Make it unambiguously clear that each method is tested, both for both true and false return values except you need not show the insert method returning false. Use the display method to show the array contents as needed.
Explanation / Answer
OrderedStringList(int size, String initialval)– constructor for the class, this initializes the internal array of Strings to have size elements, setting each of those slots to the value of initialval. Note that each array slot will need a new statement to create it and initialize it. public int size()– returns the number of elements currently in the list. public int find(String s)– returns the index location of s if it is in the list, or -1 if it is not in the list. public bool insert(String s)– adds s to the list in sorted order, returns true if successful, or false if there was not enough room allocated. public bool delete(String s)– returns true if the value s was found and removed, returns false if the value was not found. public bool deleteRange(String start, String stop)– deletes all strings within the range from strings start to stop, inclusive, and all in between. Returns true if any values were deleted, false if no strings were in the given range. *This method must use the above find and delete methods to achieve its functionality! public void displayNoLF()– uses print to show the strings in order, without index numbers, and without newlines in between them. public void display()– uses println to show the strings in order, with index numbers, spaced nicely in a vertical column. public bool merge(OrderedStringList a, OrderedStringList b)– combines the contents of the two parameter lists into the list whose method was called, initializing its allocated size to twice the current content size of a + content size of b, so only the contents of a and b remain, and c is half-full. The proper way to call this would be:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.