Question: 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

 Math 140 Programming Assignment 2 Public Methods 1. void add(String value)

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!