York U: Redefine the Possible HOME | Current Students | Faculty & Staff | Research link: Future Students, Alumni & Visitors
Search »  
Department of Computer Science and Engineering
Home
Announcements
Course Calendar
Course Forum


Y graphic
CSE 1030 - Assignment #6 - Arrays in Java - Implementing the ArrayListOfData Collection

SC/CSE 1030 - Fall 2012 - Assignment #6

Arrays in Java - Implementing the ArrayListOfData Collection



Java's Arrays are the basic building-block of many data structures. In this assignment you will use an array to implement an Array List of Data objects. An implementation for the Data class has been provided (here: Data.java, and the API is available here: Data API).

For this assignment you will need to create two classes:


ArrayListOfData.java

This class implements a collection of Data objects. The Data objects are to be stored in an array defined like this: private Data[] data;. You may not use the Java API Collections to store the Data objects (so no Array<Data>, no LinkedList<Data>, etc.) you have to store the Data objects in an array defined as above.

The API that you must implement is available here: ArrayListOfData

Some notes:

  • As Data objects are added to the ArrayListOfData class (in ArrayListOfData.add(Data datum)), the data array will have to be increased in size. It would be inefficient to increase the size by only 1 (i.e. adding one new slot to the array) every time a single new Data object needs to be added. Instead, the data array should be increased in size by a larger amount, so that the costly array resizing operation occurs less frequently.

  • The two static final values, INITIAL_ARRAY_SIZE and ARRAY_INCREMENT are both defined to have a value of 10.

    INITIAL_ARRAY_SIZE defines the size that should be used when the data array is initially created in the ArrayListOfData constructor.

    ARRAY_INCREMENT indicates by how much the size of the data array should be increased when it becomes and full (in the ArrayListOfData.add(Data datum) function, during the array resizing operation.

  • Additionally, you will also have to keep track of the number of Data objects being held in the ArrayListOfData. This number may be a different (lesser) number than the size of the data array. The ArrayListOfData.getDataObjectCount() function returns this number - the number of actual Data objects. The ArrayListOfData.getArraySize() function returns the size of the data array, which may be larger than the number of Data objects, if extra space (i.e., empty slots) exists in the data array.

  • In the ArrayListOfData.add(Data datum) function you will have to check the current size of the data array to determine whether there is enough space to insert the new Data object. If there is not enough space, then the data array will have to be resized to a larger size. Then the new data item can be placed into the next available empty slot in the array.

  • Your implementation must allow the user to store 'null' objects in the ArrayListOfData collection.


ArrayListOfDataIterator.java

This class must implement the Iterator interface that has been provided (the source code for the interface is here: Iterator.java, and the API is available here: Iterator API).

The API that you must impelement is available here: ArrayListOfDataIterator

Some notes:

  • The ArrayListOfDataIterator must implement the provided Iterator interface.

  • When the ArrayListOfDataIterator object is created, it is given access to the data array and the count of how many Data objects are stored in the data array, from the ArrayListOfData object (see the constructor for the ArrayListOfDataIterator class, and the ArrayListOfData.getIterator() function). The ArrayListOfDataIterator uses these to return one Data object at a time through the ArrayListOfDataIterator.next() function. To accomplish this, the ArrayListOfDataIterator object will have to maintain a counter, so it knows which Data objects have already been provided to whomever is using the iterator.

  • Note that the ArrayListOfDataIterator does not need to perform a deep copy of the data array it receives from the ArrayListOfData object - to keep things fast, just keeping the data array object provided to the ArrayListOfDataIterator constructor is fine for this assignment.

To complete this assignment, you must do these things:

  1. Implement the required two classes, matching the details in the APIs:
    ArrayListOfData
    ArrayListOfDataIterator

    You are responsible for defining and managing the data members of these classes that you will need, and for implementing the functions described in the API.

  2. Include appropriate comments and Javadoc comments in your source code.

  3. You should test your implementation using the a6.java program.

  4. Submit your classes electronically before the deadline using the submit command:
    submit 1030 a6 ArrayListOfData.java ArrayListOfDataIterator.java



Some notes:

  1. The source code for the Data class and Iterator interface have been provided for you here:
    Data.java, Data API
    Iterator.java, Iterator API.

    Note that you should not need to change this class and interface to complete this assignment.

  2. You will find the following class useful for testing your code: a6.java. This program provides a simple command-line interface to several tests to help you test your code.

  3. Your source code should be well organised and documented.

  4. Remember the Course's, Department's, and the University's policies on academic honesty - do your own assignment yourself. (Besides, doing it yourself is the only way to learn!)

  5. This assignment is due on Friday November 9, at noon. Late assignments will not be accepted.
    Start Early - Don't leave your assignment to the last minute!

  6. Remember that you can use the submit command more than once - subsequent submissions will replace previous submissions. So if you make a mistake, don't panic, just fix it, and resubmit it (before the deadline).

    Note that you do not need to submit both of the classes at once, you can use the submit command to submit each Java file seperately, if that is more convenient for you.

    Additional information regarding the submit command can be found by typing man submit at the command line.

  7. Do not use the Type package, nor its earlier incarnation, the york package.

  8. Your programs must compile and run on the Prism computers.

  9. Your grade will be a number from 0 to 10 - approximately one mark each for passing the tests in the a6.java program. The breakdown is:
    1 mark for creating an ArrayListOfData class that we can instantiate.
    1 mark if we can insert some Data objects into the ArrayListOfData object.
    1 mark if the ArrayListOfDataIterator handles the case where the ArrayListOfData object is empty.
    1 mark for a working ArrayListOfDataIterator.
    1 mark if the ArrayListOfData object preserves the insertion order of the Data objects, and allows duplicates.
    1 mark if the ArrayListOfData object properly resizes the data array when there's too much data for its current size.
    1 mark if the ArrayListOfData and ArrayListOfDataIterator objects properly handle a large amount of data.
    1 mark if the ArrayListOfData and ArrayListOfDataIterator objects properly handle 'null' objects.
    2 marks for coding style (nicely organised code with comments).

  10. Have FUN!






graphic rule