Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Math 140 Programming Assignment 2 Public Methods 1. void add(String value) If size 2 list.length then call the ensureCapacity method to double the size of

image text in transcribed

Math 140 Programming Assignment 2 Public Methods 1. void add(String value) If size 2 list.length then call the ensureCapacity method to double the size of the list array. After guaranteeing the list array has sufficient capacity, insert value at position size in the list array and then increase size by 1. Example: Suppose list (xyz", "cat", "123", null) and size 3. After calling add"ABC"), list ("yz","cat', "123", "ABC") and size 4. 2. void add(int index, String value) If index size then throw an IndexOutOfBoundsException. If size 2 list.length then call the ensureCapacity method to double the size of the list array. After guaranteeing the list array has sufficient capacity, insert value at position index in the list array and then increase size by 1. Example of throwing the exception: if (index size) throw new IndexOutofBoundsException(); Example: Suppose lists {"xyz", "cat", "123"). After calling add(2, "ABC"), list = {"xyz", "cat", "ABC", "123"} 3. String remove(int index) If index - size then throw an ndexOutOfBoundsException. Otherwise, remove the value stored at index by shifting the values stored in list to the left, decrease size by 1, and return the String removed by the method. Example: Suppose list ('xyz","cat", "ABC", "123") and size 4 After calling remove(2), list ("xyz"', "cat", "123"), size 3, return "ABC" 4. boolean remove(String s) If s is in the list then remove the first occurrence of s, decrease size by 1, and return true. Otherwise, return false. Example: Suppose list-("xyz", "cat", "ABC", "123"), size-4 After calling remove("ABC"), list #: ("xyz", "cat", "123") , size-3, return true

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

3. What changes should I be making?

Answered: 1 week ago

Question

2. Why?

Answered: 1 week ago