edit* I have to produce code as per the Javadoc comments.
Ok, managed to get straight into 3rd year at University studying Computing after very little Java, so i'm struggling! I'm working my way through 'Data Structures and the Java Collections' by William J Collins (recommended reading) but I'm not taking a lot of it in as of yet.
Please help!! Question under the code I have attempted so far.
Oh, sorry if this I have posted this in the wrong section.
In this project you will get to be developer of a parameterized class, and become a user of
that class. To start with, here are method specifications for the parameterized class,
Sequence, with E the type parameter:
public class Sequence<E> { protected E[] data; protected int size; /** * Initialises this Sequence object to be empty, with an initial * capacity of ten elements. */ public Sequence() { E[] data = (E[]) new Object[10]; int size = 0; } /** * Initialises this Sequence object to be empty, with a specified * initial capacity. * * @param capacity - the initial capacity of this Sequence object. * * @throws IllegalArgumentException - if capacity is non-positive */ public Sequence (int capacity){ capacity = 0; throw new IllegalArgumentException(); } /** * Returns the number of elements in this Sequence object. * * @return the number of elements in this Sequence object. */ public int size (){ return 0; } /** * Appends a specified element to this Sequence object. * * @param element - the element to be inserted at the end of this * Sequence object. */ public void append (E element) { } /** * Returns the element at a specified index in this Sequence object. * The worstTime(n) is constant, where n is the number of elements in * this Sequence object. * * @param k - the index of the element returned. * * * @return the element at index k in this Sequence object. * * @throws IndexOutOfBoundsException - if k is either negative or * greater than or equal to the number of elements in this * Sequence object. */ public E get (int k){ //Week 3 Laboratory – COMP09044 Page 2 return null; } /** * Changes the element at a specified index in this Sequence object. * The worstTime(n) is constant, where n is the number of elements in * this Sequence object. * * @param k - the index of the element required. * @param newElement - the element to replace the element at index k * in this Sequence object. * * @throws IndexOutOfBoundsException - if k is either negative or * greater than or equal to the number of elements in this * Sequence object. */ public void set (int k, E newElement){ } }
Part 1: Create unit tests based on the method specifications and stubs.
Part 2: Define the methods in the Sequence class.
Hint: use the following fields:
protected E[] data;
protected int size; // The number of elements in the Sequence, not
// the capacity of the data array.
Note 1: for the append method, if the data array is currently full, its capacity must be
increased before the element can be appended. See Programming Exercise 2.10 to see how
to accomplish the expansion.
Note 2: for methods that may throw an exception, do not include catch blocks. Instead, the
exception will be propagated, so the handling can be customised for the application.
Part 3: Test the method definitions in your Sequence class.