ava code Objectives •Use an abstract data type for a list •Use a method that contains an Object type as a formal parameter •Use methods in an existing class •Access data members within a class Required Files: •ListInterface.java •ListException.java •ListOutOfBoundsException.java •ListArrayBased.java Description A list is an abstract data type used to st
Write Java code
Objectives
•Use an abstract data type for a list
•Use a method that contains an Object type as a formal parameter
•Use methods in an existing class
•Access data members within a class
Required Files:
•ListInterface.java
•ListException.java
•ListOutOfBoundsException.java
•ListArrayBased.java
Description A list is an abstract data type used to store ordered data, and contains operations that fall into the following categories: (1) add data to a data collection, (2) remove data from a data collection, and (3) ask questions about data in a data collection. The operations which ask questions about the data in a data collection may include operations that determine if a data collection is empty, determine the size of a data collection, and retrieve the item at a given position in a data collection. A list should be able to contain any type of object. The methods for the List support any object as specified in the interface. In this assignment, the objects will be S trings.
class ListDriver
•The purpose of the ListDriver class is to perform ADT list operations on a list of objects of type String.
•The data that is to be used for the list is located in an array that is hard coded into the main method, which should include the name of each the grocery item from the example used in our discussion on the ADT: List. •An instance of ListArrayBased is passed to various methods within the ListDriver class along with other arguments needed for the method to perform its task. Appropriate comments are included for each method. •You will add code to the various methods in the ListDriver class so that each one performs its task as specified.
part 3 of the code in the pictures
* position pos. */
public void removeItem(ListArrayBased list, int pos){
TO DO: add code here
}
/* * removeAllItems *
* Precondition: a reference to a list *
* Postcondition: all items currently stored in the list * are removed */
public void removeAllItems(ListArrayBased list){
// TO DO: add code here
}
} // end of class ListArrayBasedDriver
Step by step
Solved in 2 steps