List Exercises
- How can we ensure a first-come, first-served order is maintained in the list (i.e. the first person to join the waiting list should be the first person served) ?
- Create a BlueJ project, then download and extract the jar file for the Video Inventory program into that folder.
Define a method in ListReferenceBased: insertAtEnd(Object item)
that uses the add method as a helper method and adds the new item at the end of the list.
Modify the addToWaitingList method of StockItem class, so that it adds an item to the waiting list by invoking your new method insertAtEnd.
- How can we ensure that duplicate items do not get inserted into the list?
- Define a method in ListReferenceBased: insertNoDuplicates that receives an item as parameter and inserts the item into a sorted list such that the list remains sorted and duplicates are not allowed. Hint: you may use the given insert method as a helper method (it inserts the new item into a sorted list so that the list remains sorted, but it allows duplicates), and define your own helper method to see if the item to be inserted already exists in the list.
- Modify your addAccount method of Bank2 (the one that defines accounts as ListReferenceBased) so that it calls insertNoDuplicates (described above) to keep the collection of accounts sorted by ID, while disallowing two accounts with the same ID.