Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class ObjectArray {private final int INITIAL_ARRAY_SIZE = 10;private fina

ID: 3545997 • Letter: P

Question

public class ObjectArray {private final int INITIAL_ARRAY_SIZE = 10;private final int ARRAY_EXPAND = 20;private Object[] myObjects = new Object[INITIAL_ARRAY_SIZE];private int currentObject;/** Default constructor that creates* that creates myInts with* INITIAL_ARRAY_SIZE (THIS IS A CONSTANT)* all initialized to zero*/public ObjectArray() {myObjects = new Object[INITIAL_ARRAY_SIZE];currentObject = 0;}/** This Constructor that creates myInts* with the specified initialArraySize* all initialized to 0*/public ObjectArray(int initialArraySize) {myObjects = new Object[initialArraySize];currentObject = 0;}/** This constructor creates myInts with the* enough spaces to hold the given integerArray* array.*/public ObjectArray(Object[] objectArray) {myObjects = new Object[objectArray.length];System.arraycopy(objectArray, 0, myObjects, 0, objectArray.length);currentObject = objectArray.length;}/** This part add integer to myInts and update currentInt.* If myInts is not bigger enough then,* the array will have to be resized by* adding ARRAY_EXPAND entries* that is why we use the* currentInt + ARRAY_EXPAND* this means 10 + 20 = 30* then myInts became a new array sized*/public void addObeject(Object object) {Object[] temp;if (currentObject == myObjects.length) {temp = new Object[currentObject + ARRAY_EXPAND];System.arraycopy(myObjects, 0, temp, 0, myObjects.length);temp[currentObject++] = object;myObjects = temp;} elsemyObjects[currentObject++] = object;}/** This part add the given intergerArray* to myInts and update currentInt* If there is not enough room in myInts,* the array will have to be resized by* adding the appropriate multiple* of ARRAY_EXPAND entries*/public void addObjects(Object[] objectArray) {for (int i = 0; i < objectArray.length; i++)addObeject(objectArray[i]);}/** THis part delete the integer* at the given index for example,* this part was hard to figure out* because the loop wasn't working* in an appropriate way.*/public void deleteObject(int index) {int i=0;int j=0;Object temp[] = new Object[myObjects.length];while (i < myObjects.length) {if(index != i) {temp[j++] = myObjects[i++];} else {i++;if(i != myObjects.length) {temp[j++] = myObjects[i++];} else {if(index == i){if(i != myObjects.length){i++;} else {break;}}}}}myObjects = temp;}/** This part delete the integers count* starting at the given index.* also it verify that the given index exists in myInts* The if statement make sure that goes from* small to large and not in reverse*/public void deleteObjects(int index, int count) {if (index > count){System.out.println("Error, the Index should be greater that the count");}else{int del = (count - index) + 1;for (int i = 0; i < del ; i++){deleteObject(index);}}}//it return myIntspublic Object[] getArray(){return myObjects;}/** Compare two VariableArrays objects for equality.* They will be considered equal,* if and only if both have the same number* of integers and all their entries are equal.*/public boolean equals(ObjectArray otherObjectArray) {if (getCurrentObject() != otherObjectArray.getCurrentObject())return false;elsefor (int i = 0; i < currentObject; i++)if (myObjects[i] != otherObjectArray.myObjects[i])return false;return true;}/** This method returns the integer located at the given index.* This method verify that the given index is before currentInt* and within the bounds of the size of myInts.* If an error happen,then this method return -99999.*/public Object getObjectAt(int index) {if (index<myObjects.length){return myObjects[index];}else{return -9999;}}//it return the currentIntpublic Object getCurrentObject() {return currentObject;}/** This method prints out* myInts and currentInt*/public int getObjectArrayLength(){return myObjects.length;}public void setNumberOfObjects(int currentObject){this.currentObject = currentObject;}public int getNumberOfObjects(){return currentObject;}public void showAll() {for (int i = 0; i < ((int) currentObject); i++)System.out.println(myObjects[i]);}}My program is suppose to do thisObjectArray (10 poobjects)Consider a class that maintains an array of Objects's. The class has the following private attributes:INITIAL_ARRAY_SIZE - a constant set to 10ARRAY_EXPAND - a constant set to 20myObjects - 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(int[] 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.

I think the delete functions are wrong

Explanation / Answer

// I've changed your delete functions and I'm posting only those functions here

public void deleteObject(int index) {

int i = 0;

int j = 0;

Object temp[] = new Object[myObjects.length];

if(index>=myObjects.length){

System.out.println("Index should be smaller than length");

return;

}

while (i < myObjects.length) {

if (index != i) {

temp[j] = myObjects[i];

j++

}

i++;

}

myObjects = new Objects[j-1];//Compress myObjects to j-1 objects

currentObject = temp[j-1];//Update the current Object

myObjects = temp;

}


/** This part delete the integers count* starting at the given index.* also it verify that the given index exists in myInts* The if statement make sure that goes from* small to large and not in reverse*/

public void deleteObjects(int index, int count) {

int del = count + index;/** We want to delete count items starting from index. So, last index to be deleted will be count + index**/

for (int i = 0; i < count; i++) {//Delete count number of objects.

deleteObject(index);//Always delete object at position index,, because deleteObject shifts the objects to left

}

}