SlideShare a Scribd company logo
1 of 13
Download to read offline
Given the following class in Java :
public class ThreeTenDynArray<T> {
//default initial capacity / minimum capacity
private static final int MIN_CAPACITY = 2;
//underlying array for storage -- you MUST use this for credit!
//Do NOT change the name or type
private T[] data;
private int size = 0;
private int capacity = 0;
// ADD MORE PRIVATE MEMBERS HERE IF NEEDED!
/**
*
*/
@SuppressWarnings("unchecked")
public ThreeTenDynArray() {
// Constructor
// Initial capacity of the storage should be MIN_CAPACITY
// Hint: Can't remember how to make an array of generic Ts? It's in the textbook...
data = (T[])(new Object[MIN_CAPACITY]);
size = 0;
capacity = MIN_CAPACITY;
}
/**
* @param initCapacity
*/
@SuppressWarnings("unchecked")
public ThreeTenDynArray(int initCapacity) {
// Constructor
// Initial capacity of the storage should be initCapacity.
// - Throw IllegalArgumentException if initCapacity is smaller than
// MIN_CAPACITY 2
// - Use this _exact_ error message for the exception
// (quotes are not part of the message):
// "Capacity must be at least 2!"
if (initCapacity < MIN_CAPACITY) {
throw new IllegalArgumentException("Capacity must be at least 2!");
}
}
/**
* @return
*/
public int size() {
// Report the current number of elements
// O(1)
return size; //default return, remove/change as needed
}
/**
* @return
*/
public int capacity() {
// Report max number of elements of the current storage
// (subject to change since this is a _dynamic_ )
// O(1)
return capacity; //default return, remove/change as needed
}
/**
* @param index index you're changing
* @param value what you're adding
* @return the old item at the index
*/
public T set(int index, T value) {
// Replace the item at the given index to be the given value.
// Return the old item at that index.
// Note: You cannot add new items (i.e. cannot increase size) with this method.
// O(1)
//return firstIndexOf(value);
// - Throw IndexOutOfBoundsException if index is not valid
// - Use this code to produce the correct error message for
// the exception (do not use a different message):
// "Index: " + index + " out of bounds!"
if (index < 0 && index >= size) {
throw new IndexOutOfBoundsException("Index: " + index + " out of bounds!");
}
// - Throw IllegalArgumentException if value is null.
// - Use this _exact_ error message for the exception
// (quotes are not part of the message):
// "Cannot include null values!"
if (value==null) {
throw new IllegalArgumentException("Cannot include null values!");
}
T oldValue = data[index];
data[index] = value;
return oldValue; //default return, remove/change as needed
}
/**
* @param index
* @return
*/
public T get(int index) {
// Return the item at the given index
if (index < 0 && index >= size) {
throw new IndexOutOfBoundsException("Index: " + index + " out of bounds!");
}
// O(1)
// Use the exception (and error message) described in set()
// for invalid indicies.
return data[index]; //default return, remove/change as needed
}
/**
* @param value
*/
@SuppressWarnings("unchecked")
public void append(T value) {
// Append an element to the end of the storage.
// Double the capacity if no space available.
// Code reuse! Consider using setCapacity (see below).
// For a null value, use the same exception and message
// as set().
// You can assume we will never need to grow the capacity to a value
// beyond Integer.MAX_VALUE/4. No need to check or test that boundary
// value when you grow the capacity.
// Amortized O(1)
// - Throw IllegalArgumentException if value is null.
// - Use the same error message as set().
if (value==null) {
throw new IllegalArgumentException("Cannot include null values!");
}
if (size < capacity) {
data[size] = value;
size++;
}
else{
capacity *= 2;
T[] data2 = (T[])(new Object[capacity]);
for (int i =0; i < data.length; i++) {
data2[i] = data[i];
}
data = data2;
data[size] = value;
size++;
}
}
/**
* @param index
* @param value
*/
@SuppressWarnings("unchecked")
public void insert(int index, T value) {
// Insert the given value at the given index and shift elements if needed.
// You _can_ append items with this method.
// Double capacity if no space available.
// Assume the same as append() for the upper bound of capacity.
// Code reuse! Consider using setCapacity (see below).
// For an invalid index or a null value, use the same exception and message
// as set(). However, remember that the condition of the exception is
// different (a different invalid range for indexes).
if (index >= capacity || index < 0 ) {
throw new IndexOutOfBoundsException("Index: " + index + " out of bounds!");
}
for (int i = size-1; i >= index; i--) {
data[i+1] = data[i];
}
data[index] = value;
size++;
// O(N) where N is the number of elements in the storage
}
/**
* @param index
* @return
*/
@SuppressWarnings("unchecked")
public T remove(int index) {
// Remove and return the element at the given index. Shift elements
// to ensure no gap. Throw an exception when there is an invalid
// index (see set(), get(), etc. above).
// Halve capacity (rounding down) of the storage if the number of elements falls
// below or at 1/4 of the capacity.
// However, capacity should NOT go below MIN_CAPACITY.
// Code reuse! Consider using setCapacity (see below).
// O(N) where N is the number of elements currently in the storage
if (index >= capacity || index < 0 ) {
throw new IndexOutOfBoundsException("Index: " + index + " out of bounds!");
}
T oldValue = data[index];
for (int i = index; i < data.length-1; i++) {
data[i] = data[i + 1];
}
size--;
if(size<=capacity/4)
{
capacity/=2;
if(capacity<MIN_CAPACITY)
capacity = MIN_CAPACITY;
}
return oldValue ; //default return, remove/change as needed
}
/**
* @param newCapacity
* @return
*/
@SuppressWarnings("unchecked")
public boolean setCapacity(int newCapacity) {
// Change the max number of items allowed before next expansion to newCapacity.
// No other changes to the current values in storage
// (i.e. they should all keep the same index).
// Capacity should not be changed if:
// - newCapacity is below MIN_CAPACITY; or
// - newCapacity is not large enough to accommodate current number of items
// Return false if newCapacity cannot be applied; return true otherwise.
// Special case: if newCapacity is identical to the current max number of items,
// no need to change anything but still return true.
// O(N) where N is the number of elements in the array
if (newCapacity < MIN_CAPACITY || newCapacity < size) {
return false; //default return, remove/change as needed
}
else if (newCapacity == size) {
return true;
}
return false;
}
/**
* @param value
* @return
*/
public int firstIndexOf(T value) {
// Return the index of the first occurrence of value or -1 if not found.
// NOTES: - Remember null is not a valid item in list.
// - Remember to use .equals for comparison of non-null values.
// O(N) where N is the number of elements in the list
if (value==null) {
return -1;
}
return -1; //default return, remove/change as needed
}
Please explain these errors and how to fix them.
Errors when testing:
1) test_append3(ThreeTenDynArrayTester)
java.lang.NullPointerException: Cannot read the array length because "this.data" is null
at ThreeTenDynArray.append(ThreeTenDynArray.java:161)
at ThreeTenDynArrayTester.test_append3(ThreeTenDynArrayTester.java:146)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja
va:77)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
rImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at
org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:7
4)
2) test_setCapacity1(ThreeTenDynArrayTester)
java.lang.AssertionError: Capacity failed to grow, expected capacity 8
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.assertTrue(Assert.java:41)
at ThreeTenDynArrayTester.test_setCapacity1(ThreeTenDynArrayTester.java:694)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja
va:77)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
rImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at
org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:7
4)
3) test_constructor2(ThreeTenDynArrayTester)
java.lang.AssertionError: Initial capacity of the storage has incorrect initCapacity
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.assertTrue(Assert.java:41)
at ThreeTenDynArrayTester.test_constructor2(ThreeTenDynArrayTester.java:90)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja
va:77)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
rImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at
org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:7
4)
Given the following class in Java-  public class ThreeTenDynArray-T- {.pdf

More Related Content

Similar to Given the following class in Java- public class ThreeTenDynArray-T- {.pdf

4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdfmumnesh
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdffirstchoiceajmer
 
AnswerNote Driver class is not given to test the DoubleArraySeq..pdf
AnswerNote Driver class is not given to test the DoubleArraySeq..pdfAnswerNote Driver class is not given to test the DoubleArraySeq..pdf
AnswerNote Driver class is not given to test the DoubleArraySeq..pdfnipuns1983
 
@author Derek Harter @cwid 123 45 678 @class .docx
@author Derek Harter  @cwid   123 45 678  @class  .docx@author Derek Harter  @cwid   123 45 678  @class  .docx
@author Derek Harter @cwid 123 45 678 @class .docxadkinspaige22
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfaksahnan
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
I really need help with my C++ assignment. The following is the info.pdf
I really need help with my C++ assignment. The following is the info.pdfI really need help with my C++ assignment. The following is the info.pdf
I really need help with my C++ assignment. The following is the info.pdfwasemanivytreenrco51
 
all i need is these two filesCreate VectorContainer.hppCreat.docx
all i need is these two filesCreate VectorContainer.hppCreat.docxall i need is these two filesCreate VectorContainer.hppCreat.docx
all i need is these two filesCreate VectorContainer.hppCreat.docxjack60216
 
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
 PriorityQueue.cs   Jim Mischel using System; using Sy.pdf PriorityQueue.cs   Jim Mischel using System; using Sy.pdf
PriorityQueue.cs Jim Mischel using System; using Sy.pdfrajat630669
 
Given the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docxGiven the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docxshericehewat
 
On the code which has a class in which I implementing a binary tree .pdf
On the code which has a class in which I implementing a binary tree .pdfOn the code which has a class in which I implementing a binary tree .pdf
On the code which has a class in which I implementing a binary tree .pdfwasemanivytreenrco51
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdffsenterprises
 
Use a simple vector you created before to create two other more
Use a simple vector you created before to create two other more Use a simple vector you created before to create two other more
Use a simple vector you created before to create two other more steviesellars
 
in c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdfin c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdfstopgolook
 
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfModifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfLalkamal2
 
Stack Implementation
Stack ImplementationStack Implementation
Stack ImplementationZidny Nafan
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfaucmistry
 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxalanfhall8953
 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfamirthagiftsmadurai
 

Similar to Given the following class in Java- public class ThreeTenDynArray-T- {.pdf (20)

4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdf
 
AnswerNote Driver class is not given to test the DoubleArraySeq..pdf
AnswerNote Driver class is not given to test the DoubleArraySeq..pdfAnswerNote Driver class is not given to test the DoubleArraySeq..pdf
AnswerNote Driver class is not given to test the DoubleArraySeq..pdf
 
Link list
Link listLink list
Link list
 
@author Derek Harter @cwid 123 45 678 @class .docx
@author Derek Harter  @cwid   123 45 678  @class  .docx@author Derek Harter  @cwid   123 45 678  @class  .docx
@author Derek Harter @cwid 123 45 678 @class .docx
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
I really need help with my C++ assignment. The following is the info.pdf
I really need help with my C++ assignment. The following is the info.pdfI really need help with my C++ assignment. The following is the info.pdf
I really need help with my C++ assignment. The following is the info.pdf
 
all i need is these two filesCreate VectorContainer.hppCreat.docx
all i need is these two filesCreate VectorContainer.hppCreat.docxall i need is these two filesCreate VectorContainer.hppCreat.docx
all i need is these two filesCreate VectorContainer.hppCreat.docx
 
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
 PriorityQueue.cs   Jim Mischel using System; using Sy.pdf PriorityQueue.cs   Jim Mischel using System; using Sy.pdf
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
 
Given the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docxGiven the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docx
 
On the code which has a class in which I implementing a binary tree .pdf
On the code which has a class in which I implementing a binary tree .pdfOn the code which has a class in which I implementing a binary tree .pdf
On the code which has a class in which I implementing a binary tree .pdf
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
 
Use a simple vector you created before to create two other more
Use a simple vector you created before to create two other more Use a simple vector you created before to create two other more
Use a simple vector you created before to create two other more
 
in c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdfin c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdf
 
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfModifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
Given the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdfGiven the code below create a method called, getCollisionCount that .pdf
Given the code below create a method called, getCollisionCount that .pdf
 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdf
 

More from NicholasflqStewartl

he amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdfhe amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdfNicholasflqStewartl
 
Having a hard time with this one- Fill in the blanks with the follow.pdf
Having a hard time with this one-   Fill in the blanks with the follow.pdfHaving a hard time with this one-   Fill in the blanks with the follow.pdf
Having a hard time with this one- Fill in the blanks with the follow.pdfNicholasflqStewartl
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfNicholasflqStewartl
 
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdfHarriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdfNicholasflqStewartl
 
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdfHardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdfNicholasflqStewartl
 
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdfGovernment and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdfNicholasflqStewartl
 
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdfHammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdfNicholasflqStewartl
 
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdfHacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdfNicholasflqStewartl
 
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdfGiven the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdfNicholasflqStewartl
 
Grouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdfGrouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdfNicholasflqStewartl
 
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdfGuessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdfNicholasflqStewartl
 
Given the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdfGiven the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdfNicholasflqStewartl
 
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdfGreener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdfNicholasflqStewartl
 
Given the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdfGiven the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdfNicholasflqStewartl
 
Given Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdfGiven Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdfNicholasflqStewartl
 
Give concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdfGive concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdfNicholasflqStewartl
 
Given a stream of strings- remove all empty strings- import java-uti.pdf
Given a stream of strings- remove all empty strings-   import java-uti.pdfGiven a stream of strings- remove all empty strings-   import java-uti.pdf
Given a stream of strings- remove all empty strings- import java-uti.pdfNicholasflqStewartl
 
Given an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdfGiven an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdfNicholasflqStewartl
 
Given a string- does -oce- appear in the middle of the string- To defi.pdf
Given a string- does -oce- appear in the middle of the string- To defi.pdfGiven a string- does -oce- appear in the middle of the string- To defi.pdf
Given a string- does -oce- appear in the middle of the string- To defi.pdfNicholasflqStewartl
 
Give examples of species interactions that might be recognizable in th.pdf
Give examples of species interactions that might be recognizable in th.pdfGive examples of species interactions that might be recognizable in th.pdf
Give examples of species interactions that might be recognizable in th.pdfNicholasflqStewartl
 

More from NicholasflqStewartl (20)

he amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdfhe amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdf
 
Having a hard time with this one- Fill in the blanks with the follow.pdf
Having a hard time with this one-   Fill in the blanks with the follow.pdfHaving a hard time with this one-   Fill in the blanks with the follow.pdf
Having a hard time with this one- Fill in the blanks with the follow.pdf
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
 
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdfHarriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
 
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdfHardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
 
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdfGovernment and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
 
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdfHammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
 
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdfHacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdf
 
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdfGiven the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
 
Grouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdfGrouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdf
 
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdfGuessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
 
Given the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdfGiven the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdf
 
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdfGreener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
 
Given the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdfGiven the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdf
 
Given Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdfGiven Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdf
 
Give concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdfGive concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdf
 
Given a stream of strings- remove all empty strings- import java-uti.pdf
Given a stream of strings- remove all empty strings-   import java-uti.pdfGiven a stream of strings- remove all empty strings-   import java-uti.pdf
Given a stream of strings- remove all empty strings- import java-uti.pdf
 
Given an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdfGiven an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdf
 
Given a string- does -oce- appear in the middle of the string- To defi.pdf
Given a string- does -oce- appear in the middle of the string- To defi.pdfGiven a string- does -oce- appear in the middle of the string- To defi.pdf
Given a string- does -oce- appear in the middle of the string- To defi.pdf
 
Give examples of species interactions that might be recognizable in th.pdf
Give examples of species interactions that might be recognizable in th.pdfGive examples of species interactions that might be recognizable in th.pdf
Give examples of species interactions that might be recognizable in th.pdf
 

Recently uploaded

When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 

Recently uploaded (20)

When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 

Given the following class in Java- public class ThreeTenDynArray-T- {.pdf

  • 1. Given the following class in Java : public class ThreeTenDynArray<T> { //default initial capacity / minimum capacity private static final int MIN_CAPACITY = 2; //underlying array for storage -- you MUST use this for credit! //Do NOT change the name or type private T[] data; private int size = 0; private int capacity = 0; // ADD MORE PRIVATE MEMBERS HERE IF NEEDED! /** * */ @SuppressWarnings("unchecked") public ThreeTenDynArray() { // Constructor // Initial capacity of the storage should be MIN_CAPACITY // Hint: Can't remember how to make an array of generic Ts? It's in the textbook... data = (T[])(new Object[MIN_CAPACITY]); size = 0; capacity = MIN_CAPACITY; } /**
  • 2. * @param initCapacity */ @SuppressWarnings("unchecked") public ThreeTenDynArray(int initCapacity) { // Constructor // Initial capacity of the storage should be initCapacity. // - Throw IllegalArgumentException if initCapacity is smaller than // MIN_CAPACITY 2 // - Use this _exact_ error message for the exception // (quotes are not part of the message): // "Capacity must be at least 2!" if (initCapacity < MIN_CAPACITY) { throw new IllegalArgumentException("Capacity must be at least 2!"); } } /** * @return */ public int size() { // Report the current number of elements // O(1) return size; //default return, remove/change as needed }
  • 3. /** * @return */ public int capacity() { // Report max number of elements of the current storage // (subject to change since this is a _dynamic_ ) // O(1) return capacity; //default return, remove/change as needed } /** * @param index index you're changing * @param value what you're adding * @return the old item at the index */ public T set(int index, T value) { // Replace the item at the given index to be the given value. // Return the old item at that index. // Note: You cannot add new items (i.e. cannot increase size) with this method. // O(1) //return firstIndexOf(value); // - Throw IndexOutOfBoundsException if index is not valid // - Use this code to produce the correct error message for // the exception (do not use a different message):
  • 4. // "Index: " + index + " out of bounds!" if (index < 0 && index >= size) { throw new IndexOutOfBoundsException("Index: " + index + " out of bounds!"); } // - Throw IllegalArgumentException if value is null. // - Use this _exact_ error message for the exception // (quotes are not part of the message): // "Cannot include null values!" if (value==null) { throw new IllegalArgumentException("Cannot include null values!"); } T oldValue = data[index]; data[index] = value; return oldValue; //default return, remove/change as needed } /** * @param index * @return */ public T get(int index) { // Return the item at the given index if (index < 0 && index >= size) { throw new IndexOutOfBoundsException("Index: " + index + " out of bounds!");
  • 5. } // O(1) // Use the exception (and error message) described in set() // for invalid indicies. return data[index]; //default return, remove/change as needed } /** * @param value */ @SuppressWarnings("unchecked") public void append(T value) { // Append an element to the end of the storage. // Double the capacity if no space available. // Code reuse! Consider using setCapacity (see below). // For a null value, use the same exception and message // as set(). // You can assume we will never need to grow the capacity to a value // beyond Integer.MAX_VALUE/4. No need to check or test that boundary // value when you grow the capacity. // Amortized O(1) // - Throw IllegalArgumentException if value is null. // - Use the same error message as set(). if (value==null) {
  • 6. throw new IllegalArgumentException("Cannot include null values!"); } if (size < capacity) { data[size] = value; size++; } else{ capacity *= 2; T[] data2 = (T[])(new Object[capacity]); for (int i =0; i < data.length; i++) { data2[i] = data[i]; } data = data2; data[size] = value; size++; } } /** * @param index * @param value */ @SuppressWarnings("unchecked") public void insert(int index, T value) {
  • 7. // Insert the given value at the given index and shift elements if needed. // You _can_ append items with this method. // Double capacity if no space available. // Assume the same as append() for the upper bound of capacity. // Code reuse! Consider using setCapacity (see below). // For an invalid index or a null value, use the same exception and message // as set(). However, remember that the condition of the exception is // different (a different invalid range for indexes). if (index >= capacity || index < 0 ) { throw new IndexOutOfBoundsException("Index: " + index + " out of bounds!"); } for (int i = size-1; i >= index; i--) { data[i+1] = data[i]; } data[index] = value; size++; // O(N) where N is the number of elements in the storage } /** * @param index * @return */ @SuppressWarnings("unchecked")
  • 8. public T remove(int index) { // Remove and return the element at the given index. Shift elements // to ensure no gap. Throw an exception when there is an invalid // index (see set(), get(), etc. above). // Halve capacity (rounding down) of the storage if the number of elements falls // below or at 1/4 of the capacity. // However, capacity should NOT go below MIN_CAPACITY. // Code reuse! Consider using setCapacity (see below). // O(N) where N is the number of elements currently in the storage if (index >= capacity || index < 0 ) { throw new IndexOutOfBoundsException("Index: " + index + " out of bounds!"); } T oldValue = data[index]; for (int i = index; i < data.length-1; i++) { data[i] = data[i + 1]; } size--; if(size<=capacity/4) { capacity/=2; if(capacity<MIN_CAPACITY) capacity = MIN_CAPACITY; }
  • 9. return oldValue ; //default return, remove/change as needed } /** * @param newCapacity * @return */ @SuppressWarnings("unchecked") public boolean setCapacity(int newCapacity) { // Change the max number of items allowed before next expansion to newCapacity. // No other changes to the current values in storage // (i.e. they should all keep the same index). // Capacity should not be changed if: // - newCapacity is below MIN_CAPACITY; or // - newCapacity is not large enough to accommodate current number of items // Return false if newCapacity cannot be applied; return true otherwise. // Special case: if newCapacity is identical to the current max number of items, // no need to change anything but still return true. // O(N) where N is the number of elements in the array if (newCapacity < MIN_CAPACITY || newCapacity < size) { return false; //default return, remove/change as needed } else if (newCapacity == size) { return true;
  • 10. } return false; } /** * @param value * @return */ public int firstIndexOf(T value) { // Return the index of the first occurrence of value or -1 if not found. // NOTES: - Remember null is not a valid item in list. // - Remember to use .equals for comparison of non-null values. // O(N) where N is the number of elements in the list if (value==null) { return -1; } return -1; //default return, remove/change as needed } Please explain these errors and how to fix them. Errors when testing: 1) test_append3(ThreeTenDynArrayTester) java.lang.NullPointerException: Cannot read the array length because "this.data" is null at ThreeTenDynArray.append(ThreeTenDynArray.java:161) at ThreeTenDynArrayTester.test_append3(ThreeTenDynArrayTester.java:146)
  • 11. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja va:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso rImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:7 4) 2) test_setCapacity1(ThreeTenDynArrayTester) java.lang.AssertionError: Capacity failed to grow, expected capacity 8 at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.assertTrue(Assert.java:41) at ThreeTenDynArrayTester.test_setCapacity1(ThreeTenDynArrayTester.java:694) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja va:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso rImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568)
  • 12. at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:7 4) 3) test_constructor2(ThreeTenDynArrayTester) java.lang.AssertionError: Initial capacity of the storage has incorrect initCapacity at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.assertTrue(Assert.java:41) at ThreeTenDynArrayTester.test_constructor2(ThreeTenDynArrayTester.java:90) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja va:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso rImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:7 4)