Question: Implement a Positional List using an array 1. Create 2 classes called ArrayPositionalList with a nested class Locus that implement the PositionalList and Position interfaces
Implement a Positional List using an array 1. Create 2 classes called ArrayPositionalList with a nested class Locus that implement the PositionalList and Position interfaces respectively. 2. Demonstrate your implementation by rewriting the Scoreboard example from L02. Use a PositionalList for the board, and in a PartB_Driver class use the players from the notes to demo (build the scoreboard in any way then add Jill and remove Paul). Note that all methods will be tested by your marker. To implement the ArrayPositionalList, use both the LinkedPositionalList and ArrayList implementations as a guide. a) Add the nested Locus class. Locus implements the Position interface (just like Node in a linked positional list). Note that there is no next or prev, but only an integer index b) Add the fields and constructors: - an array of Locus objects - a constant CAPACITY defaulted at 16, size field - 2 constructors: no-arg and capacity as a parameter c) Add your size() and isEmpty() methods d) Implement the methods: Start with first() and last() : how would you get the first and last elements from an array? This should form a basis of how to move from linked to array. From there you can start thinking about how to convert all the methods from linked-based to array-based. To consider: with LinkedPositionalList , you get the previous and next positions through the node (which is a Position ) and getNext() and getPrev() methods. With ArrayPositionalList you get the next and previous through the Position as well, but with the getIndex() and the array. Instead of simply calling node.next() you will find out what locus.getIndex() is, then return the Locus at the next index of your array. Notes: - you will need a way to validate and explicitly cast Position objects to Locus objects in order to use Locus methods like getIndex() - many methods declare exceptions in its signature: most can be handled in common private utility methods - The index field of the Locus class needs to be updated with any methods that require a shift in elements - Your data structure should be dynamic: grows and shrinks according to size/capacity Suggestions: - Override the toString method to display both index and element i.e. an ArrayPositionalList populated with names [0] Harry [1] Ron [2] Hermione [3] Neville [4] Luna - Can be helpful for testing/debugging - Test each individual method as you write it
public interface Position
public interface PositionalList
int size();
boolean isEmpty();
Position
Position
Position
Position
Position
Position
Position
Position
E set(Position
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
