Question
The NumArrayList class has a single private instance variable L of type ArrayList where T is a type that extends the abstract class Number. For
The NumArrayList class has a single private instance variable L of type ArrayList
You will complete the assignment by writing the following methods for the NumArrayList class:
public NumArrayList(): The default constructor for the class. It instantiates the internal ArrayList L in the NumArrayList object by making an appropriate call to the ArrayList constructor.
public NumArrayList(T[] initValues): The parameterized constructor for the class. It instantiates the internal ArrayList L in the NumArrayList object by making an appropriate call to the ArrayList constructor. It then places the values in the array initValues into the new ArrayList object L.
public void add(T elem): The method adds the parameter to the internal ArrayList object L.
public T get(int index): The method returns the element found in the internal ArrayList object L in position index.
public String toString(): This method returns a String containing the elements found in the internal ArrayList object L. The elements should be separated by a space and the String should end with a newline.
public NumArrayList
import java.util.ArrayList;
public class NumArrayList
private ArrayList
public NumArrayList() {
}
// Create a new NumArrayList, initializing it with the parameter
public NumArrayList(T[] initValues) {
}
public void add(T elem) {
}
public T get(int index) {
//
//}
// Return the String representation of the NumArrayList
public String toString() {
// replace this with the correct implementation
return "";
}
// Multiply the NumArrayList by an Integer value
public NumArrayList
// replace this with the correct implementation
NumArrayList
// Put your code to fill the NumArrayList iItem here
return iItem;
}
}
TEST
public class TestNumArrayList {
public static final int arrSize = 10;
public static void main(String[] args) {
Integer[] iarr = new Integer[arrSize];
for (int i = 0; i < arrSize; i++)
iarr[i] = new Integer(1 + (int) (100 * Math.random()));
NumArrayList
System.out.println("The Integer NumArrayList: " + iArrLst);
NumArrayList
for (int i = 0; i < arrSize; i++)
dArrLst.add(new Double(100* Math.random()));
System.out.println("The Double NumArrayList: ");
// Put this code back in when you write the get method
/*for (int i = 0; i < arrSize; i++)
System.out.printf("%.2f ", dArrLst.get(i));
System.out.println();*/
NumArrayList
System.out.println("The result of calling iMult: " + secIArrLst);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started