
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
![Write a Java program to work with two arrays and perform operations on them.
Your program should have 2 methods:
int[] union (int[] al, int[] a2): takes two integer arrays and returns a new
integer array consisting of all ints that appear in either a1 or a2. The returned array
should be appropriately sized and should contain any duplicate ints since everything
from both a1 and a2 should be in there. The returned array should not have any empty
spots and should be sorted numerically.
●
●
int[] intersection (int[] al, int[] a2): takes two integer arrays and returns a
new integer array consisting of all ints that appear in both a1 and a2. The returned array
should be appropriately sized and sorted numerically, and it should not contain any
duplicate ints or empty spots.
For example, when a1 = {1,2,3,4,5} and a2 {1,5,6,7,8}, union (al, a2) will return
{1,1,2,3,4,5,5,6,7,8} and intersection (al, a2) will return {1,5}.
=
Provide the following menu using a do..while loop in the main method to the user.
1. Union
2. Intersection
3. Exit
Before the menu pops up for the user, the main method should collect the input for the 2
arrays and create the arrays. After the user picks a menu choice, the main method should call
the appropriate method to do the work requested. Since these methods return new arrays to
the caller, the printing of the output of the new array should also be done by the main method.](https://content.bartleby.com/qna-images/question/8b3d603c-82f6-465f-a9d5-589cd2e4d33b/7f866e03-34f6-4c7f-99c9-fa4f333ab8df/mvbjjcrc_thumbnail.jpeg)
Transcribed Image Text:Write a Java program to work with two arrays and perform operations on them.
Your program should have 2 methods:
int[] union (int[] al, int[] a2): takes two integer arrays and returns a new
integer array consisting of all ints that appear in either a1 or a2. The returned array
should be appropriately sized and should contain any duplicate ints since everything
from both a1 and a2 should be in there. The returned array should not have any empty
spots and should be sorted numerically.
●
●
int[] intersection (int[] al, int[] a2): takes two integer arrays and returns a
new integer array consisting of all ints that appear in both a1 and a2. The returned array
should be appropriately sized and sorted numerically, and it should not contain any
duplicate ints or empty spots.
For example, when a1 = {1,2,3,4,5} and a2 {1,5,6,7,8}, union (al, a2) will return
{1,1,2,3,4,5,5,6,7,8} and intersection (al, a2) will return {1,5}.
=
Provide the following menu using a do..while loop in the main method to the user.
1. Union
2. Intersection
3. Exit
Before the menu pops up for the user, the main method should collect the input for the 2
arrays and create the arrays. After the user picks a menu choice, the main method should call
the appropriate method to do the work requested. Since these methods return new arrays to
the caller, the printing of the output of the new array should also be done by the main method.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- In java i have some code for a method that finds the index of an integer that is passed in thet int is (target) the method also has the array called (array) and the first and last element of the array. also for this method to work the array has to be in descending order "static int find(int [] array, int first, int last, int target)" thats the method with all the variables that are passed to it my guess is that the first if statement just will have a short line that is "return -1;" because since the array has to be in descending order the first element cant be greater then the last element in the array but im confused on the rest because i cant find a way to make them one line codes with the conditions that i have to meet in the comments any help would be aprreaciatedarrow_forwardWrite a Java program to make two arrays containing random integer values (You can make these arrays with specific sizes using the below makeRandomArray method). The program should sum these two arrays and prints the resulted array (the array that contains the result of the two arrays summing). The program should also show the maximum element of the resulted array. Your program must define and call the following methods to perform the program as illustrated above: 1- A method int [] makeRandomArray(int size ,int a , int b) that makes and returns an array with specific size. The methods fills this array with random integers in a range [a..b] 2- A method public static int findmax(int x[ ]) that finds the maximum value of a number of x array passed to the method. 3- A method public static void printArray(int x[ ]) that prints the elements of the array x passed to the method. 4- A method public int[ ] sumTwoArrays(int x[ ], int y[ ]) that sums the elements of the two arrays(x and y…arrow_forwardWrite the Java method averageOfDoubles that is passed an array of double values, and returns the average of the array values.You can assume the array length is a positive integer.arrow_forward
- Write a program to test your implementation by reading data related to 50 Car objects and store them in an array ARR of Car. Your program should include:a. A method Search() that takes as parameters an array of Car objects ARR and a Car object C. This method should return true if C is inside ARR, false otherwise. b. A method findCylinders that takes as parameters an array of Car objects ARR and number of cylinder engine N. It should display all the cars that have N cylinder engine.arrow_forwardA class Date has methods intgetMonth() and intgetDay(). Write a method public boolean has3OnSameDay(Date[] birthdays) that returns true if at least three birthdays in the array fall on the same date. Your method should work in O(n) time, where n = birthdays.length.arrow_forwardWrite a Java program that reads an integer N from the user and declares an integer array of size N. It then inputs N non-negative integers from the user into the array and do the following: 1. Finds and prints the minimum, maximum, sum, and average of the numbers. 2. Displays array data as a histogram – graphically by plotting each numeric value as a bar of asterisks (*) as shown in the example diagram. This is somehow similar to Lab11 Sample output 9 Enter the size of array: Enter 9 integer values: 10 19 14 Minimum -o Maximum - 19 = 68 Sum Average = 7.55 ========== Histogram: - ------= Element Ualue Hintogran 19 ***** ***** 11arrow_forward
- Write a Java method (do not write a class, only the method) with the following signature: Return type: void Parameters: 2D integer array Name: printDiagonal Implement the method code that will print out the values of the 2D array along the Diagonal from left to right. For example, if the array had the following values: 56 78 98 21 33 55 98 44 11 The method should print to the console: 56,33,11 The above 2D array example is only given for you to understand the problem Do not hard code the values in your solution or assume the array is the same as the given data. Your method should work for all 2D integer arrays.arrow_forwardFor java. Refer to picture.arrow_forwardCreate a Java program that will perform the following statements.Perform the following items in a continuous manner. The code solution for the next item will be basedon the code performed on the previous item.1. Create an ArrayList named “apostles” and add the following names to it: Juan, Pedro, Lucas,Judas, Mateo, Marcos and Simon.2. Print the size of the ArrayList to the standard output before and after adding the names.3. Use two methods to print the names in standard output.a. Using For loopb. Using Iterator4. Add the name “Philip” at the end, and add the name “Thomas” between the two names “Juan”and “Pedro”.5. Remove the name “Judas” using its index position.6. Search the names “Marcos”, “James” and “Judas” in the ArrayList “apostles”This part will display the following:Does “apostles” contains Marcos? _______ (it will return a Boolean result)Does “apostles” contains James? _______Does “apostles” contains Judas? _______7. Sort the names of the ArrayList in alphabetical order.8.…arrow_forward
- java a. A method named contains exists that takes an array of Strings and a single String, in that order, as arguments and returns a boolean value that is true if the array contains the given String. Assume that an array of Strings named names is already declared and initialized. Call the method to see if the array contains the name "Fred", and save the result in a new variable named fredIsHere. b. Given a method named printMessage that takes a String argument and returns nothing, call the method to print out "I love Java!".arrow_forwardhelp asaparrow_forwardUse java.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education