Question: Modify the ListInterface Java interface. 1) change Object to Comparable 2) change the name of the interface from ListInterface to ComparableListInterface // ******************************************************** // Interface

Modify the ListInterface Java interface.

1) change Object to Comparable

2) change the name of the interface from ListInterface to ComparableListInterface

// ******************************************************** // Interface ListInterface for the ADT list. // ******************************************************** public interface ListInterface { public boolean isEmpty(); public int size(); public void add(int index, Object item) throws ListIndexOutOfBoundsException, ListException; public Object get(int index) throws ListIndexOutOfBoundsException; public void remove(int index) throws ListIndexOutOfBoundsException; public void removalAll(); } //end ListInterface

Modify the ListArrayBased class

Modify ListArrayBased by performing the following:

1) change the name of the class from ListArrayBased to ComparableListArrayBased

2) change ListInterface to ComparableListInterface

3) change Object to Comparable

4) add a method corresponding to the following UML:

+isInAscendingOrder() : boolean {query}

isInAscendingOrder returns true if the list is in ascending sorted order, else returns false

// ************************************************************* // Array-based implementation of the ADT list. // ************************************************************* public class ListArrayBased implements ListInterface { private static final int MAX_LIST = 50; private Object items[]; // an array of list items private int numItems; // number of itmes in list public ListArrayBased() { items = new Object[MAX_LIST]; numItmes = 0; } // end default constructor public boolean isEmpty() { return (numItems ==0); } // end isEmpty public int size() { return numItems; } // end size public void removeAll() { // Creates a new array; marks old array for // garbage collection. items = new Object[MAX_LIST]; numItems = 0; } // end removeAll public void add (int index, Object item) throws ListIndexOutOfBoundsException { if (numItems >= MAX_LIST) { throw new ListException("ListException on add"); } // end if if (index >= 0 && index <= numItems) { // make room for new element by shifting all items at // positions >= index toward the end of the // list (no shift if index == numItems+1) for (int pos = numItems - 1; pos >= index; pos--) { items[pos+1] = items[pos]; } // end for // insert new items items[index] = item; numItems++; } else { // index out of range throw new ListIndexOutOfBoundsException( "ListIndexOutOfBoundsException on add"); } // end if } // end add public Object get(int index) throw ListIndexOutOfBoundsException { if (index >= 0 && index < numItems) { return items[index]; } else { // index out of range throw new ListIndexOutOfBoundsException( "ListIndexOutOfBoundsException on get"); } // end if } // end get public void remove(int index) throw ListIndexOutOfBoundsException { if (index >= 0 && index < numItems) { // delete item by shifting all items at // positions > index towards the beginning of the list // (no shift if index == size) for (int pos = index + 1; pos < numItems; post++) { items[pos-1] = items[pos]; } // end for numItems--; } else { // index out of range throw new ListIndexOutOfBoundsException( "ListIndexOutOfBoundsException on remove"); } // end iff } // end remove } // end ListArrayBased

Test your solution by writing a driver program. The driver program will have a main() method and is the program that is run at the command line. You may give your driver program any name you like. The driver program should perform a loop, ask for input, and display output in the following way (note that the output in bold is what the user inputs):

Input a list of integers: 5 9 101 183 4893

Your list of integers is in ascending order.

Do you want to continue (y/n): y

Input a list of integers: 5 9 101 183 48

Your list of integers is not in ascending order.

Do you want to continue (y/n): y

Input a list of integers: 5 4 100 101 183 4893

Your list of integers is not in ascending order.

Do you want to continue (y/n): y

Input a list of integers: 5 9 101 101 183 4893

Your list of integers is in ascending order.

Do you want to continue (y/n): y

Input a list of integers: -48 -7 0 5 9 101 183

Your list of integers is in ascending order.

Do you want to continue (y/n): y

Input a list of integers: 14

Your list of integers is in ascending order.

Do you want to continue (y/n): y

Input a list of integers:

Your list of integers is in ascending order.

Do you want to continue (y/n): n

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!