List Exercises
For this exercise, you will need the list-related classes (ListArrayBased.java, ListException.java, ListIndexOutOfBoundsException.java, ListInterface.java) on the chapter 4 examples link as well as
ListReferenceBased.java and
Node.java.
You may choose ONE of the following (1 or 2):
- For the Bank program:
- Create concrete class Bank1 that implements your BankInterface such that the collection of accounts is stored in a ListArrayBased. Create concrete class Bank2 that implements your BankInterface such that the collection of accounts is stored in a ListReferenceBased. Test with TestBank1 and TestBank2.
- The search method can be a linear search. Binary search works well (efficiently) on arrays but not lists, because arrays allow direct access to any element whereas lists do not. You may ignore for this exercise the binary search and the sorting of accounts.
== OR ==
- For the Explore (Game) program:
- Complete the definition of the class CreatureCollectionListBased which implements CreatureCollectionInterface. The data type of the attribute creatures will be ListInterface; initialize it in the constructor: this.creatures = new ListArrayBased();
- Modify Island so that the data type of its attribute creatures is ListInterface and modify its constructor so that the collection of creatures is initialized by invoking the constructor of CreatureCollectionListBased.
- Run the main method of Driver. The game should work as before, only now the creatures are stored in Island using a list ADT (that is array based).
- Update the constructor of CreatureCollectionListBased to say: this.creatures = new ListReferenceBased();
- Run the main method of Driver. The game should work as before, only now the creatures are stored in Island using a list ADT (that is reference based).