Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3 ArrayLists 3.1 Write code that creates an ArrayList object named list and fills list with these numbers (using one or a pair of for

3 ArrayLists

3.1 Write code that creates an ArrayList object named list and fills list with these numbers (using one or a pair

of for or while loops):

0 1 2 3 4 0 1 2 3 4

3.2 Consider the ArrayList object named list containing these Integers:

list = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 }

What are the contents of list after this loop completes?

for (int i = 1; i < 10; ++i) {

list.set(i, list.get(i) + list.get(i-1));

}

3.3 Write an enhanced for loop that counts how many numbers in an ArrayList object named list are negative.

Print the count after the loop terminates.

3.4 Write a method named arrayListSum() that has one parameter pList which is an object of the class ArrayList

. The method shall return the sum of the elements of pList.

3.5 Write a method named named arrayListCreate() that has two int parameters pLen and pInitValue. The method shall

create and return a new ArrayList object which has exactly pLen elements. Each element shall be initialized

to pInitValue.

3.6 Write a void method named insertName() that has two input parameters: (1) pList which is an object of ArrayList

where each element of pList is a person's name; and (2) a String object named pName. Assume the names in

pList are sorted into ascending order. The method shall insert pName into pList such that the sort order is maintained.

3.7 Write a void method named arrayListRemove() which has two parameters: pList is an object of the ArrayList

class and pValue is an int. The method shall remove all elements from pList that are equal to pValue.

-------------------------------------------------------------------

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

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

What is the purpose of a mock-up?

Answered: 1 week ago