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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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