This Problem Set Is Due By 11:59 PM on November 10, 2013

  1. ObjectArray (10 points)

    Consider a class that maintains an array of Objects's. The class has the following private attributes:

    • INITIAL_ARRAY_SIZE - a constant set to 10
    • ARRAY_EXPAND - a constant set to 20
    • myObjects - an array of Object's that is initialized to INITIAL_ARRAY_SIZE with all the entries set to null.
    • currentObject - an int indicating the index of the current Object. This attribute should be initialized to 0, the location of where the next Object will be added.

    And the following methods:

    • ObjectArray() - Default constructor that creates myObjects with INITIAL_ARRAY_SIZE entries, all initialized to null.
    • ObjectArray(int initialArraySize) - Constructor that creates myObjects with the specified initalArraySize entries, all initialized to null.
    • ObjectArray(Object[] objectArray) - Constructor that creates myObjects with the enough space to hold the given objectArray array. all entries are initialized from the given objectArray array. Make sure to also initialize currentObject appropriately.
    • addObject(Object object) - Add object to myObjects and update currentObject. If there is no room in myObjects, the array will have to be resized by adding ARRAY_EXPAND entries.
    • addObjects(Object[] objectArray) - Add the given objectArray to myObjects and update currentObject. If there is not enough room in myObjects, the array will have to be resized by adding the appropriate multiple of ARRAY_EXPAND entries.
    • deleteObject(int index) - Delete the object at the given index. Make sure to compress myObjects and update currentObject. You must also verify that the given index exists in myObjects.
    • deleteObjects(int index, int count) - Delete the count objects starting at the given index. Make sure to compress myObjects and update currentObject. You must also verify that the given index exists in myObjects and that there are count entries starting from there.
    • equals(Object other) - Compare two ObjectArray's objects for equality. They will be considered equal, if and only if both are the same size, have the same number of objects and all their entries are equal.
    • getObjectAt(int index) - This method returns the object located at the given index. This method must verify that the given index is before currentObject and within the bounds of the size of myObjects. In case of an error, this method should return null.
    • getNumberOfObjects() - This method returns the currentObject.
    • getObjectArrayLength() - This method returns the length of myObjects.
    • showAll() - This method displays all information about myObjects by using the toString() method of each object and displaying currentObject.

    Implement this class in Java and test it with the ObjectArrayDemo provided by your instructor.

    Name this class ObjectArray
    Place this class in the edu.cuny.lehman.cmp326.sales package.

Please submit the completed assignment on Blackboard by attaching all your .java files. Make sure to attach all your programs to each submission.