Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Create an Intellij project 2. Add this import to Main.java: import java.util.ArrayList; 3. In class Main, (a) Add the following method to the main

1. Create an Intellij project

2. Add this import to Main.java:

import java.util.ArrayList;

3. In class Main,

(a) Add the following method to the main class. When called, it will insert pseudo-random integer values into the ArrayList passed via the parameter al. The number of values inserted is determined by the value passed to the parameter size.

public static void Pack(ArrayList al, int size) {

Random r = new Random();

for (int i=0; i

al.add(r.nextInt(size));

}

(b) In method main:

i. Create two ArrayList instance objects and the related reference variables.

ii. Ask the user for the number of integers to place in the ArrayLists and, in turn, pass the two ArrayList instances along with the value the user entered to method Pack to place random integers in each.

iii. Create a third ArrayList instance object and related reference variable. Write the Java code to copy all of the values that both of the two original ArrayList instance objects into the third (just created) ArrayList instance object. Do not copy a value into the third ArrayList instance object if it is already present in that ArrayList.

iv. Output the number of common values and the common values stored in the third ArrayList instance object.

image text in transcribed

ExampleRun #Luserinputin red); How many integers? 25 Values in Common: 12 [16, 7, 3, 6, 18, 23, 13, 2, 14, 12, 24, 17] Example Run #2 (user input in red): How many integers? 50 Values in Common: 18 125, 32, o, 30, 22, 49, 41, 18, 35, 11, 5, 43, 48, 7, 33, 9, 3, 28] Example Run #3 (user input in red): How many integers? 15 Values in Common: 6 17, 12, 11, 10, 1, 8]

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

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions