SlideShare a Scribd company logo
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

PDF
Given the following errors and class in Java- How are these errors fix.pdf
PDF
This file contains a complete array-based MultiSet, but not the code.pdf
PDF
this file has a complete array-based MultiSet, but not the code need.pdf
PDF
Here is what I got so far, I dont know how to write union, interse.pdf
PDF
template-typename T- class Array { public- ---------------------------.pdf
PDF
public class DoubleArraySeq implements Cloneable {    Priva.pdf
PDF
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
PDF
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Given the following errors and class in Java- How are these errors fix.pdf
This file contains a complete array-based MultiSet, but not the code.pdf
this file has a complete array-based MultiSet, but not the code need.pdf
Here is what I got so far, I dont know how to write union, interse.pdf
template-typename T- class Array { public- ---------------------------.pdf
public class DoubleArraySeq implements Cloneable {    Priva.pdf
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf

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

PDF
4. The size of instructions can be fixed or variable. What are advant.pdf
PDF
Everything needs to be according to the instructions- thank you! SUPPO.pdf
PDF
AnswerNote Driver class is not given to test the DoubleArraySeq..pdf
PPT
Link list
DOCX
@author Derek Harter @cwid 123 45 678 @class .docx
PDF
So I have this code(StackInAllSocks) and I implemented the method but.pdf
PDF
ReversePoem.java ---------------------------------- public cl.pdf
PDF
I really need help with my C++ assignment. The following is the info.pdf
DOCX
all i need is these two filesCreate VectorContainer.hppCreat.docx
PDF
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
PDF
On the code which has a class in which I implementing a binary tree .pdf
PDF
Were writing code for a project that dynamically allocates an arra.pdf
DOCX
Use a simple vector you created before to create two other more
PDF
in c languageTo determine the maximum string length, we need to .pdf
PDF
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
PPT
Stack Implementation
PDF
Given the code below create a method called, getCollisionCount that .pdf
PDF
using the code below write the public V add(K key, V value); that ad.pdf
PDF
#include stdafx.h#include iostreamusing namespace std;cl.pdf
PDF
Implement the sequence class from Section 3.2 of the textbook. The d.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
AnswerNote Driver class is not given to test the DoubleArraySeq..pdf
Link list
@author Derek Harter @cwid 123 45 678 @class .docx
So I have this code(StackInAllSocks) and I implemented the method but.pdf
ReversePoem.java ---------------------------------- public cl.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
PriorityQueue.cs Jim Mischel using System; using Sy.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
Use a simple vector you created before to create two other more
in c languageTo determine the maximum string length, we need to .pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
Stack Implementation
Given the code below create a method called, getCollisionCount that .pdf
using the code below write the public V add(K key, V value); that ad.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdf
Implement the sequence class from Section 3.2 of the textbook. The d.pdf

More from NicholasflqStewartl (20)

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

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
01-Introduction-to-Information-Management.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
RMMM.pdf make it easy to upload and study
PPTX
Pharma ospi slides which help in ospi learning
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Lesson notes of climatology university.
PDF
Classroom Observation Tools for Teachers
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Final Presentation General Medicine 03-08-2024.pptx
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
01-Introduction-to-Information-Management.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Microbial disease of the cardiovascular and lymphatic systems
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
GDM (1) (1).pptx small presentation for students
RMMM.pdf make it easy to upload and study
Pharma ospi slides which help in ospi learning
Supply Chain Operations Speaking Notes -ICLT Program
Lesson notes of climatology university.
Classroom Observation Tools for Teachers
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Microbial diseases, their pathogenesis and prophylaxis
Chinmaya Tiranga quiz Grand Finale.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF

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)