Question: Question 2: A 1D-array with distinct elements can be used to represent a set. Write an interactive Java program that prompts for and reads the


Question 2:
A 1D-array with distinct elements can be used to represent a set. Write an interactive Java program that
prompts for and reads the sizes of two 1D-arrays and then it prompts for and reads distinct values in each of the
two arrays. It then does the following:
. It calls a static method theUnion passing to it the two arrays. The method returns a reference to a 1D-
array that contains the set union of the two arrays.
. It displays the elements in the set union.
Note:
. Your program must use appropriate loops.
. Assume that the sizes read are each greater or equal to zero.
. Enter distinct elements in the two arrays and do not test whether the elements are distinct or not.
(i.e., assume that the user will enter distinct elements).
. The array reading must be done in the main method and not in the theUnion static method.
. The method theUnion must not contain calls to I/O methods.
. The created set union must have distinct elements (i.e., each element must not be repeated.)
Sample program runs:



Question 1: (a) A model of world population, in billions of people, is given by the equation: population = 5.5 * e0.017st Where t is the time in years t 0 represents January 1993, t1 represents January 1994, etc). Write a Java static method getYearAndPopulation that takes as input a future population x in billions of people, it then returns the year in which the world population will exceed x and the world population in that year. Your method must throw an IllegalArgumentException if its input is less or equal to 5.5 Note: Since a Java method returns either no value or it returns a single value, use a two-element array to return the two values
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
