Create a new numarraylist initializing it with the parameter

Assignment Help Computer Engineering
Reference no: EM132084470

The NumArrayList class has a single private instance variable L of type ArrayList<T> where T is a type that extends the abstract class Number.

For example, both Integer and Double extend Number.

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<Integer> 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 intValue() method of the T class in order to implement this method.

import java.util.ArrayList;

public class NumArrayList<T extends Number>{

private ArrayList<T> L;

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<Integer> iMult(Integer val) {

// replace this with the correct implementation

NumArrayList<Integer> iItem = new NumArrayList<Integer>();

// 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<Integer> iArrLst = new NumArrayList<>(iarr);

System.out.println("The Integer NumArrayList: " + iArrLst);

NumArrayList<Double> dArrLst = new 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\n", dArrLst.get(i));

System.out.println();*/

NumArrayList<Integer> secIArrLst = iArrLst.iMult(arrSize);

System.out.println("The result of calling iMult: " + secIArrLst);

}

}

Reference no: EM132084470

Questions Cloud

Construct a recurrence relation for the number of atoms : The number of atoms of a strange element on Earth per hour is the average of the number of atoms in two previous hours.
How does the number of bits used in addressing : How does the number of bits used in addressing (i.e. the size of a pointer) affect addressable RAM size and thus maximum program size?
Is the number of zeros equal to number of ones : Is the number of zeros equal to number of ones in a finite binary string written on the tape of Turing machine? Draw state diagram.
Discuss the outcomes of the treaty of versailles : Discuss the outcomes of the Treaty of Versailles and how these led to the outbreak of World War II?
Create a new numarraylist initializing it with the parameter : The NumArrayList class has a single private instance variable L of type ArrayList where T is a type that extends the abstract class Number.
Impact of the crusades on europe and the western world : What is The impact of the Crusades on Europe and the western world?
Roman catholic church : Do you think Dante was trying to support the Roman Catholic Church with his writing( inferno ), or was his story doing something different?
The term deterministic turing machine : What is the meaning / historical background behind the term deterministic turing machine (DTM)?
Impact of decolonization on britain : Describe in detail the impact of decolonization on Britain and France from 1954 to 1965. Was decolonization the result of European initiatives

Reviews

Write a Review

Computer Engineering Questions & Answers

  What are the main advantages and disadvantages of zigbee

What are the main advantages and disadvantages of ZigBee? Of near-field communications? Broadband wireless service supports what kind of applications?

  List and describe the six addressing modes of the processor

List and briefly describe the 6 addressing modes of the x86 processor. Description should include how an operand is formed and where it operates on memory.

  Explain why are exceptions particularly suitable for

question 1 why are exceptions particularly appropriate for dealing with errors produced by methods of classes in the

  List some of the trends in processor design

In recent year it has been seen that processor performance. List some of trends in processor design resulting from this basic factor related to VLSI technology.

  What levels of osi model tcp/ip functions

Use short answers to define the difference (including the advantages and disadvantages of) between.

  For this discussion respond to the followingdiscuss the use

for this discussion respond to the followingdiscuss the purpose of subnetting.discuss the use of arp tcp udp ftp http

  Write a divide-and-conquer algorithm that solves the problem

A tromping is a group of three unit squares arranged in an L-shape. Write a divide-and-conquer algorithm that solves this problem.

  Why is contingency planning important for management

Why is contingency planning important for management? Specifically in the Information Technology field or department.

  Define a class for rational numbers

Define a class for rational numbers. A rational number is a number that can be represented as the quotient of two integers. For example, 1/2, 3/4, 64/2.

  How does one evaluate types of tracking beacon variable pass

How does one evaluate the types of tracking beacon variables passed to the analytics platform collection servers? How do tracking beacon audits help ensure reliable data collection?

  Program has to convert feet into meters

The program must also convert feet into meters. The program prompts the user to enter a number in feet, converts it to meters, and displays the result. One foot is 0.305 meters.

  Create a program to find the number of intersecting pairs

Create a program to find the number of intersecting pairs among a set of N random lines, each line generated with random integer coordinates between 0 and 1000.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd