Java All classes must be named as shown in the above UML diagram except the concrete child classes. The ItemList is a singly-linked list with the following methods: • insert(index: int, item: Item) : boolean o Inserts the given item at the given index if an equal item is not already in the list. If the method is successful it returns true. If an equal item already exists in the list or the index is out of range, this method returns false. • add(item: Item): boolean o Adds the given item to the front of the list. Returns true if successful and false if an equal item is already in the list. • set(index: int, item: Item) : Item o Replaces the object in the list at the given index with this object. If the index is out of range or the given item is already in the list, the method returns null. If the operation is successful, the method returns the object that was replaced by this one. • delete(index: int) : Item o Deletes the object at the given index from the list. If the index is out of range, the method returns null. If the operation is successful, the method returns the object that was deleted. • remove(item: Item) : boolean o Removes the given item from the list. If the object does not exist in the list, the method returns false. If the operation is successful, the method returns true. • report(index: int) : Item o Reports the object in the list at the given index. If the index is out of range, returns null. • find(item: Item) : int o Finds the given item in the list and returns the index where it was found. Returns -1 if it is not found. • size() : int o Reports the number of elements currently stored in the list. • toString() : String o Reports a String representation of the list of objects currently stored in it, in the format [first item String, second item String, …, last item String] where each item is displayed using their toString method. • getTotalCost(): double o Reports the total of all the cost field values of all the items in the list. • getTotalValue(): double o Reports the total of the retail prices of all the items in the list, as reported by each item's calcPrice method. Include any added expense as reported by the calcAddedExpense() method if the item is an instance of the SpecialtyItem class.
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
Trending now
This is a popular solution!
Step by step
Solved in 3 steps