Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Explain. Thanks! TestNumArrayList.Java package hw8; public class TestNumArrayList { public static final int arrSize = 10; public static void main(String[] args) { Integer[] iarr

Please Explain. Thanks!

image text in transcribed

TestNumArrayList.Java

package hw8;

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 (iarr); System.out.println("The Integer NumArrayList: " + iArrLst); NumArrayList dArrLst = new NumArrayList(); for (int i = 0; i

NumArrayList.java

// To use or not as you wish package hw8;

import java.util.ArrayList;

public class NumArrayList{

private ArrayList L;

public NumArrayList() {

} // Create a new NumArrayList, initializing it with the parameter public NumArrayList(T[] initValues) { } public void add(T elem) { } // Uncomment out and write this method // There isn't a reasonable stub I can put in it //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 iMult(Integer val) { // replace this with the correct implementation NumArrayList iItem = new NumArrayList(); // Put your code to fill the NumArrayList iItem here return iItem; } }

Assignment For this assignment you will write a class NumArrayList which is a generic type for an ArrayList that contains numeric values. I have provided a template for the class found in the NumArrayList.java file posted to D2L. You should begin your assignment by downloading that template 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 example, both Integer and Double extend Number. You are not allowed to create any extra variables in the class, other than variables local to the methods You will complete the assignment by writing the following methods for the NumArrayList class: 1. public NumArrayList0: 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 2. 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 3. public void add(T elem): The method adds the parameter to the internal ArrayList object L 4. public T get(int index): The method returns the element found in the internal ArrayList object L in position index 5. public String toString0: 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 6. public NumArrayList iMult(Integer val): The method returns a new NumArrayList object containing Integers which is created by taking the calling NumArrayList object and multiplying each of the values found in its internal ArrayList by val. You will need to use the intValue0 method of the T class in order to implement this method I have provided a driver program (e.g. a main method that uses the NumArrayList class) TestNumArrayList java to help you test your code which has been posted to D2L. Be aware that the grader may add to that program, so if you feel that any of your methods haven't been tested effectively by the driver program, please modify as necessary. However, you should only submit the NumArrayList java class Below is the sample output that the test program produces for my solution to the NumArrayList class. Be aware that the test program puts random numbers into the lists, so the actual values you see when you run this likely will differ from what you sce below: The Integer NumArrayList: 96 98 97 2 38 66 81 31 50 48 The Double NumArrayList: 95.35 35.28 90.41 37.68 2.99 22.40 94.84 28.25 46.84 The result of calling iMult: 960 980 970 20 380 660 810 310 500 480

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

2. What role should job descriptions play in training at Apex?

Answered: 1 week ago

Question

How is slaked lime powder prepared ?

Answered: 1 week ago

Question

Why does electric current flow through acid?

Answered: 1 week ago

Question

What is Taxonomy ?

Answered: 1 week ago

Question

1. In taxonomy which are the factors to be studied ?

Answered: 1 week ago