So for this project I'm working on, I need to write the implementation for a ListADT that stores Characters. I'm pretty confused at how to approach/implement these methods. Especially for the one that is supposed to return the capacity of the array-list, which is different than the number of elements contained in the array-list. I need some help. Here's the skeleton for some context:
public interface ListADT {
* Remove all the elements of this list. Position and number of elements are
* updated but the capacity remains unchanged.
* Given ListADT bl == 3< b | a >
* When bl.clear()
* Then bl == 3< | >
*
* Given ListADT bl == 3< | >
* When bl.clear()
* Then bl == 3< | >
* }
public ListADT clear();
* get the current character. If it is not possible to get the current
* character, throw an IllegalGetException.
* Given ListADT bl == 5< b | a >
* When Character val = bl.get()
* Then val == 'a'
* }
public Character get()
throws IllegalGetException;
* Get the current capacity of the list.
* Given ListADT bl == 5< | b , a >
* When int val = bl.getCapacity()
* Then val == 5
* }
public Integer getCapacity();
* get the number of elements in the list.
* Given ListADT bl == 5< | b , a >
* When int val = bl.getNumElts()
* Then val == 2
*
* Given ListADT bl == 5< | >
* When int val = bl.getNumElts()
* Then val == 0
* }
public Integer getNumElts();
* get the current position of the list.
* Given ListADT bl == 5< b | a >
* When int val = bl.getPosition()
* Then val == 1
* }
public Integer getPosition();
* insert c into this ListADT at the current position. If the number of elements in the list
* is equal to the capacity of the list (i.e., the list is full), then the
* list should increase capacity by one to allow the insert.
* Given ListADT bl == 2< b | a >
* When bl.insert('x')
* Then bl == 3< b | x , a >
* }
public ListADT insert(Character c);
* move the current position to position 0 (the first position) of the list.
* Given ListADT bl == 5< b , a | >
* When bl.moveToFirst()
* Then bl == 5< | b , a >
* }
public void moveToFirst();
* move the current position one spot closer to the tail of the list.
* Remember that the last possible position is just after the last element.
* If it is not possible to move to the next position, leave the list as it
* is (do nothing).
* Given ListADT bl == 5< | b , a >
* When bl.next()
* Then bl == 5< b | a >
* }
*
* Given ListADT bl == 5< b , a | >
* When bl.next()
* Then bl == 5< b , a | >
* }
public void next();
* move the current position one spot closer to the head of the list. If it
* is not possible to move to the previous position, leave the list as it is
* (do nothing).
* Given ListADT bl == 5< b , a | >
* When bl.prev()
* Then bl == 5< b | a >
*
* Given ListADT bl == 5< | b , a >
* When bl.prev()
* Then bl == 5< | b , a >
* }
public void prev();
* remove the current element from this ListADT. See chapter 5 for details
* on the remove operation. If it is not possible to remove the current
* element, then leave the list alone (do nothing).
* Given ListADT bl == 5< b | a >
* When bl.remove()
* Then bl == 5< b | >
* }
public ListADT remove();
* Change the capacity of this list to c. If c is less than the current
* capacity, throw away any extra elements. If one of the extra elements was
* the current element, then set the position to after the new last element.
* Given ListADT bl == 3< b | a >
* When bl.resize(5)
* Then bl == 5< b | a >
*
* Given ListADT bl == 3< b | a >
* When bl.resize(1)
* Then bl == 1< b | >
* }
public ListADT resize(int c);
}