Public Class Arrayclass Extends Javalangobject Description Class Wrapper Java Array Additi Q43903911
public class ArrayClass
extends java.lang.Object
Description: Class wrapper for a Java array, with additionalmanagement operations
Note: Maintains a capacity value for maximum number of itemsthat can be stored, and a size value for the number of valid orviable data items in the array
Implement the followings in ArrayClass:
-
Field Detail
-
DEFAULT_CAPACITY
private static final int DEFAULT_CAPACITY
See Also:
Constant Field Values
-
FAILED_ACCESS
public static final int FAILED_ACCESS
See Also:
Constant Field Values
-
localArray
private int[] localArray
-
arraySize
private int arraySize
-
arrayCapacity
private int arrayCapacity
-
-
Constructor Detail
-
ArrayClass
public ArrayClass()
Default constructor, initializes array to default capacity(10)
-
ArrayClass
public ArrayClass(int capacity)
Initializing constructor, initializes array to specifiedcapacity
Parameters:
capacity – integer maximum capacity specification for thearray
-
ArrayClass
public ArrayClass(int capacity, int size, int fillValue)
Initializing constructor, initializes array to specifiedcapacity, size to specified value, then fills all elements withspecified size value
Parameters:
capacity – maximum capacity specification for the array
size – sets the number of items to be filled in array, and setsthe size of the ArrayClass object
fillValue – value to be placed in all elements of initializedarray up to the size
-
ArrayClass
public ArrayClass(ArrayClass copied)
Copy constructor, initializes array to size and capacity ofcopied array, then copies only the elements up to the givensize
Parameters:
copied – ArrayClass object to be copied
-
-
Method Detail
-
accessItemAt
public int accessItemAt(int accessIndex)
Accesses item in array at specified index if index within arraysize bounds
Parameters:
accessIndex – index of requested element value
Returns:
accessed value if successful, FAILED_ACCESS (-999999) if not
-
appendItem
public boolean appendItem(int newValue)
Appends item to end of array, if array is not full, e.g., nomore values can be added
Parameters:
newValue – value to be appended to array
Returns:
Boolean success if appended, or failure if array was full
-
clear
public void clear()
Clears array of all valid values by setting array size to zero,values remain in array but are not accessible
-
getCurrentCapacity
public int getCurrentCapacity()Description: Gets current capacity of array
Note: capacity of array indicates number of values the array canhold
Returns:
capacity of array
-
getCurrentSize
public int getCurrentSize()Description: Gets current size of array
Note: size of array indicates number of valid or viable valuesin the array
Returns:
size of array
-
insertItemAt
public boolean insertItemAt(int insertIndex, int newValue)Description: Inserts item to array at specified index if array isnot full, e.g., no more values can be added
Note: Value is inserted at given index, all data from that indexto the end of the array is shifted up by one
Note: Value can be inserted after the last valid element but notat any index past that point
Parameters:
insertIndex – index of element into which value is to beinserted
newValue – value to be inserted into array
Returns:
Boolean success if inserted, or failure if array was full
-
isFull
public boolean isFull()
Tests for size of array equal to capacity, no more values can beadded
Returns:
Boolean result of test for full
-
isEmpty
public boolean isEmpty()
Tests for size of array equal to zero, no valid values stored inarray
Returns:
Boolean result of test for empty
-
removeItemAt
public int removeItemAt(int removeIndex)Description: Removes item from array at specified index if indexwithin array size bounds
Note: Each data item from the element immediately above theremove index to the end of the array is moved down by oneelement
Parameters:
removeIndex – index of element value to be removed
Returns:
removed value if successful, FAILED_ACCESS (-999999) if not
-
resize
public boolean resize(int newCapacity)Description: Resets array capacity, copies current size and currentsize number of elements
Exception: Method will not resize capacity below current arraycapacity, returns false if this is attempted, true otherwise
Parameters:
newCapacity – new capacity to be set; must be larger thancurrent capacity
Returns:
Boolean condition of resize success or failure
-
Expert Answer
Answer to public class ArrayClass extends java.lang.Object Description: Class wrapper for a Java array, with additional management…
OR