Question: Write a program named Lab20A that creates an ArrayList of random numbers and processes the list. Create a void method that receives an ArrayList

Write a program named Lab20A that creates an ArrayList of random numbers and processes the list. Create a void method that receives an ArrayList of integers as a parameter and will do the following: i. Print the received ArrayList with a label stating that it is the original list ii. Create a new ArrayList named list1 that is a copy of the received ArrayList (The clone method from the video sample code could be a good way to do this. This way you will not change the original ArrayList.) iii. Create a new ArrayList named list2 that contains (0,10,20,30,40,50,60,70,80,90,100) Use this statement (and add it to your notes): ArrayList list2 = new ArrayList (Arrays.asList(0,10,20,30,40,50,60,70,80,90,100)); iv. Use the contains method to see if list1 contains 50 and print a statement to say if it does or not. v. Use the removeAll method to remove all the items from list1 that are in list2 vi. Print list1 with a label to say that the items from list2 have been removed Create an int method that receives an ArrayList of integers as a parameter and will: i. Use an iterator object to go through the ArrayList and total the values ii. Calculate and return the average of the values In the main method, i. Declare an ArrayList of integers ii. Fill the ArrayList with 20 random numbers between 0 and 100 iii. Call your first (void) method sending the ArrayList iv. Call your second (int) method sending the ArrayList and print the value it returns (with a label) v. Sort the ArrayList (using Collections.sort) vi. Print the ArrayList again
Step by Step Solution
There are 3 Steps involved in it
Here is the program named Lab20A that creates an ArrayList of random numbers and processes the list java import javautilArrayList import javautilArray... View full answer
Get step-by-step solutions from verified subject matter experts
