Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA. Remember that this is an instance method to the ArrayIntList class. There is ArrayIntList class written below the question. Also, please write comments/explanations of

JAVA. Remember that this is an instance method to the ArrayIntList class. There is ArrayIntList class written below the question.

Also, please write comments/explanations of the steps.

image text in transcribed

import java.util.*; public class ArrayIntList { private int[] elementData; // list of integers private int size; // current number of elements in the list public static final int DEFAULT_CAPACITY = 100; // pre : capacity >= 0 (throws IllegalArgumentException if not) // post: constructs an empty list with the given capacity public ArrayIntList(int capacity) { if (capacity = 0; } // pre : size()  size) { throw new IndexOutOfBoundsException("index: " + index); } ensureCapacity(size + 1); //this public method throws the exception for (int i = size; i > index; i--) { elementData[i] = elementData[i - 1]; } elementData[index] = value; size++; } // pre : 0  elementData.length) { int newCapacity = elementData.length * 2 + 1; if (capacity > newCapacity) { newCapacity = capacity; } elementData = Arrays.copyOf(elementData, newCapacity); } } // post: throws an IndexOutOfBoundsException if the given index is // not a legal index of the current list private void checkIndex(int index) { if (index = size) { throw new IndexOutOfBoundsException("index: " + index); } } } 
2. Write a method called indexOfSubList that accepts another list L as a parameter and returns the starting index of where L first appears in this list, or -1 if it is not found. All elements of L must appear in sequence and in the same order. For example, if variables called list1 and list2 store [11, -7, 3, 42, 0, 14] and [3, 42, 0], respectively, the call of listi.indexOfSubList (list2) should return 2

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

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago