Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Urgent. Just basic Java. Thank you! This lab will give you a peek under the hood of the ArrayList class, by asking you to write

Urgent. Just basic Java. Thank you!

This lab will give you a peek under the hood of the ArrayList class, by asking you to write your own version of ArrayList called ListArray.

Note that we will not be able to make our ListArray class store data of any Object type.

Later this quarter, we will learn about generics, which will allow us to alter our classes to store all Object types

For now, we will only store Strings in our ListArray.

Copy and paste the following starter code into a new class file called ListArray.java

public class ListArray { private String[] array; private int numElements; /**Constructors*/ /** * Default constructor for ListArray * Creates an empty array of length 10 * Sets numElements to 0 */ public ListArray() { } /** * Constructor for ListArray * Creates an empty array of length size * Sets numElements to 0 * @param size the initial size of the * ListArray */ public ListArray(int size) { } /** * Copy constructor for ListArray * Creates a new list array of the * same size as the ListArray passed * in as a parameter, and copies the * parameter's data into the new * list array using a for loop * Also sets the numElements to be * the same as the parameter's * numElements * @param la the ListArray to copy */ public ListArray(ListArray la) { } /**Accessor Methods*/ /** * Returns whether the list array is * currently empty * @return whether the list array is * empty */ public boolean isEmpty() { return false; } /** * Returns the current number of * elements stored in the list * array * @return the number of elements */ public int size() { return -1; } /** * Returns the element at the specified * index. Prints an error message and * returns an empty String if index is * larger than or equal to numElements * @param index the index of the element * to access * @return the element at index */ public String get(int index) {

return null;

} /** * Uses the linearSearch algorithm to * locate an element in the list array * @param str the element to locate * @return whether or not the element * is in the list array */ public boolean contains(String str) { return false; } /** * Uses the linearSearch algorithm to * locate an element in the list array * @param str the element to locate * @return the location of the element * or -1 if the element is not in the * list array */ public int indexOf(String str) { return -1; } /** * Determines whether the list array * is currently full * @return whether the list array * is at maximum capacity */ private boolean atCapacity() { return false; } /**Mutator Methods*/ /** * Resizes the list array by making a new * array that has a length (capacity) * 10 larger than the current array's * length (capacity) */ private void reSize() { } /** * Inserts a new element to the end * of the list array. * Resizes the list array if it is * at capacity before inserting * @param str the element to insert */ public void add(String str) { } /** * Inserts a new element at the specified * index in the list array. * Resizes the list array if it is * at capacity before inserting * @param index the index at which to insert * @param str the element to insert */ public void add(int index, String str) { } /** * Assigns a new value to the list array * at a specified index * @param index the index at which to update * @param str the new element */ public void set(int index, String str) { } /** * Removes an element at a specified index in * the list array * @param index the index at which to remove * @return the element that was removed */ public String remove(int index) {

return null; } /** * Removes the first instance of the specified * element in the list array * @param str the element to remove * @return whether the element was successfully * removed */ public boolean remove(String str) {

return false;

} /**Additional Methods*/ /** * Creates a String of all elements, * with [] around the elements, * each element separated from the next * with a comma */ @Override public String toString() {

return null;

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions