INFORMATION & COMPUTER SCIENCE DEPARTMENT, KFUPM
ICS202 : DATA STRUCTURES
LAB #03: Linked Lists
To study the implementation of linked-list and have a thorough understanding of its methods
To use linked-list to implement a Container
To use linked-list to implements a Searchable Container.
Download the file lab03.zip
and unzip it in the ics202 main folder.
Winzip will automatically create a subfolder lab03 and store some of the
files in that folder. After
unzipping, you should have the following files:
Under the ics202
package:
MyLinkedList.java
ListEmptyException.java
InvalidOperationException.java
Under the ics202.lab03
package:
TestMyLinkedList.java
(a) Study MyLinkedList.java carefully to make sure you understand what each of its methods is doing. The File
MyLinkedList.java contains an implementation of singly linked list as in the lecture slides, while TestMyLinkedList.java is a test
class for the MyLinkedList class, although most of the cases are not implemented.
(b)
(a)
Implement a class MyContainer2 (under ics202.lab03 package)
similar to the MyContainer we saw in the first lab, but using
MyLinkedList as the data structure.
In particular, you should implement the purge, iterator
and insert methods.
The compareTo method can be implemented to simply throw
MethodNotImplemented exception as in lab01.
(b) Copy the file TestMyContainer.java from lab01 and save it as TestMyContainer2.java in lab03 and update it accordingly to test the MyContainer2 class.
(a)
Write a class MySearchableContainer2 (under ics202.lab03
package) that extends the MyContainer2 class and implements the
SearchableContainer interface.
In particular, you should implement the isMember, find and
withdraw methods.
(b) Copy the file TestMySearchableContainer.java from lab02 and save it as TestSearchableMyContainer2.java in lab03 and update it accordingly to test the MySearchableContainer2 class.
(a) Study the given classes Item and Shop and then complete the method initializeList of TestShops.java such that it initializes
shoplist with at least three shops. Each shop's itemContainer must be initialized with at least two items.
(b) Complete the method buyItem such that it prompts the user to enter the name of an item he wants to buy, the quantity to be bought,
and the shop he will buy from. The method then sells the item by updating the stockQuantity of that item and by displaying the
required amount of money. Your method must display appropriate error messages for error cases.
(c) Complete the method displayShops such that it displays shoplist.