Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Work exercise 11.4, 11.12, and 11.14 into one program (to develop 3 methods for ArrayList: first method finds the maximum element in an array list;

Work exercise 11.4, 11.12, and 11.14 into one program (to develop 3 methods for ArrayList: first method finds the maximum element in an array list; the second method computes the sum of all elements in an array list; and the third method combines (union) two lists by adding the second list to the first list). Use Integer type for all methods. See problem statements for methods signatures and sample test data. Write one separate test program to test all three.

11.4 (Maximum element in ArrayList) Write the following method that returns the maximum value in an ArrayList of integers. The method returns null if the list is null or the list size is 0. public static Integer max(ArrayList list) Write a test program that prompts the user to enter a sequence of numbers ending with 0, and invokes this method to return the largest number in the input.

11.12 (Sum ArrayList) Write the following method that returns the sum of all numbers in an ArrayList: public static double sum(ArrayList list) Write a test program that prompts the user to enter 5 numbers, stores them in an array list, and displays their sum.

11.14 (Combine two lists) Write a method that returns the union of two array lists of integers using the following header: public static ArrayList union( ArrayList list1, ArrayList list2) For example, the union of two array lists {2, 3, 1, 5} and {3, 4, 6} is {2, 3, 1, 5, 3, 4, 6}. Write a test program that prompts the user to enter two lists, each with five integers, and displays their union. The numbers are separated by exactly one space in the output. Here is a sample run: Enter five integers for list1: 3 5 45 4 3 Enter five integers for list2: 33 51 5 4 13 The combined list is 3 5 45 4 3 33 51 5 4 13

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_2

Step: 3

blur-text-image_3

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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

What should you do in a follow-up call?

Answered: 1 week ago

Question

Compare the current team to the ideal team.

Answered: 1 week ago

Question

a. Do team members trust each other?

Answered: 1 week ago