Question: Hello, I am completely lost on how to implement the ( private static ArrayList data; // a reference to an ArrayList of String objects )

Hello,

I am completely lost on how to implement the ( private static ArrayList data; // a reference to an ArrayList of String objects ) into the methods. I've tried taking the data and turning it into an array but it becomes a mess... The driver and other codes are pertaining to the sortedstringlist are already done so I can only work with what is designated in the code... Can someone help explain how to use the ' private static ArrayList < String> data; ' ?

public class SortedStringList implements SortedStringListInterface{

private static ArrayList data; // a reference to an ArrayList of String objects

public SortedStringList()

// creates an empty list

{

} // end no-args constructor

public boolean isEmpty()

// Determines whether a list is empty

{

return true;

} // end isEmpty

public int size()

// Returns the number of items that are in a list

{

return 0;

} // end size

public void removeAll()

// Removes all the items in the list

{

} // end removeAll

public void add(String item) throws ListException

// Inserts item into its proper position in a sorted list

// Throws an exception if the item connot be placed on the list

{

try

{

}

catch(Exception e)

{

throw new ListException("Add to List failed: " + e.toString());

}

}

public String get(int index) throws ListIndexOutOfBoundsException

// Retrieves the item at position index of a sorted list, if 1 <= index <= size().

// The list is left unchanged by this operation.

// Throws an exception when index is out of range.

{

if (index > size())

{

throw new ListIndexOutOfBoundsException(index + " is an invalid index");

}

return null;

}

public void remove(String item) throws ListException

// Removes the item from a sorted list.

// Throws an exception if the item is not found.

{

try

{

}

catch(Exception e)

{

throw new ListException("Remove " + item.toString() + " from List failed: " + e.toString());

}

}

public int locateIndex(String item)

// Returns the position where the item belongs or exists in a sorted list;

// item and the list are unchanged.

{

return 0;

}

} // end SortedStringList

******************* sorted string interface ***********************************

// Interface SortedListInterface for the ADT SortedList.

// *********************************************************

public interface SortedStringListInterface

{

public boolean isEmpty();

// Determines whether a sorted list is empty

public int size();

// Returns the number of items that are in a sorted list

public void add(String item) throws ListException;

// Inserts item into it's proper position in a sorted list

// Throws an exception if the item cannot be placed on the list

public String get(int index) throws ListIndexOutOfBoundsException;

// Retrieves the item at position index of a sorted list, if 1 <= index <= size().

// The list is left unchanged by this operation.

// Throws an exception when index is out of range.

public void remove(String item) throws ListException;

// Removes the item from a sorted list.

// Throws an exception if the item is not found.

public int locateIndex(String item);

// Returns the position where the item belongs or exists in a sorted list;

// item and the list are unchanged.

public void removeAll();

// Removes all the items in the list

} // end ListInterface

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!