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

We need to write our own array list class. We will call it \"BackwardArrayList\"

ID: 3744318 • Letter: W

Question

We need to write our own array list class. We will call it "BackwardArrayList". This class will be different than a normal array list: The last box in the array will be the beginning of the list and the first box [0] will be the end of the list. ***Inverse translation *** is the user asks for a box: [0] will be 1 for the user and so on

WE ARE TO ONLY HAVE FIVE METHODS!!!! NO MORE AND USE NAMES GIVEN

-theSize: this method recieves nothing and returns an integer value of the number of integers tht are in the list (positions used).

-addSomething: we will use method overload, this method can recieve only an intege value which will be added to the beginning of the list. Or it can recieve an integer position and a integer value where the value will be placed in the position given(BOOLEAN RETURN). ONLY ONE AT A TIME AND IF A BOX IS WANTED EVERYTHING MUST SHIFT.

-removeSomething: this method will recieve only an integer value for the position of value to be removed. (shift) (return boolean) (shorten the list not the array)

-findSomething: this method will recieve the integer value you are searching for and will return the position of the first instance of that value found in the list. (starts back to front)

-makeBigger: this methd will make the current array being used fot the array list one and a half times bigger than the current size. Return a boolean value indicating the task has been done succesfully. WILL RUN AUTOMATICALLY WHEN ARRAY IS FULL. KNOW THE SIZE SO THE DECIMA WILL TRUNCATE)

***MAKE A TEST DRIVER IN ORDER TO TEST PROGRAM***

***MUST RUN FROM COMAND LINE***

***EXCEPTIONS SHOULD BE USED***

***DO NOT USE JAVA LIST INTERFACE*

** PLEASE PROGRAM THIS AND I WILL RATE WELL!! PKEASE MAKE SURE TO INCLUDE COMMENTS SO THAT I CAN UNDERSTAND WHAT IS HAPPENING AND WHERE.

Explanation / Answer

public class BackwardArrayList { private int[] arr; private int size; public BackwardArrayList() { size = 0; arr = new int[2]; } public int theSize() { return size; } public boolean addSomething(int value) { if(size == arr.length) { makeBigger(); } for(int i = size; i > 0; --i) { arr[i] = arr[i-1]; } arr[0] = value; size++; return true; } public boolean removeSomething(int value) { int index = findSomething(value); if(index == -1) { return false; } else { for(int i = index; i = 0; --i) { if(arr[i] == value) return i; } return -1; } public boolean makeBigger() { int[] newArr = new int[(int) (size*1.5)]; for(int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote