1. Write a method that returns an int array using user's inputs from the console window. The method should have the following header. The formal parameter size is the size of the return array. public static int[] inputArray (int size) 2. Write a method that calculates and returns the average of an array with the following headers. public static double average (int[] list) 3. Write a method to add two int arrays, assuming that arrays referred by variables a and b are of the same size. The header of the method is as follows. public static int[] add (int[] listl, int[] list2) The add method should return an array of the same size as the input arrays, with each element to be the sum of the elements from the input arrays. For example, if the two input arrays are [3, 5, 2, 6, 4, 9] and [1, 2, 3, 4, 5, 6], the returned sum array should be [4, 7, 5, 10, 9, 15]. 4. Write a method to display an int array's contents on the console window. The header of the method is as below. public static void displayArray (int[] list) 5. Write the main method to: a. Create two input arrays with the same size by invoking the inputArray method twice in the main method. b. Calculate the average of the first int array by invoking the average method. Display the average result on the console window. c. Calculate the array sum of both input arrays by invoking the add method. d. Display the sum array by invoking the display Array method.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question

Need help writing the code. Attatching the problem instruction and code outline and display result in the images.

1. Write a method that returns an int array using user's inputs from the console window. The
method should have the following header. The formal parameter size is the size of the return
array.
public static int[] inputArray (int size)
2. Write a method that calculates and returns the average of an array with the following headers.
public static double average (int[] list)
3. Write a method to add two int arrays, assuming that arrays referred by variables a and b are
of the same size. The header of the method is as follows.
public
static int[] add (int[] list1, int[] list2)
The add method should return an array of the same size as the input arrays, with each
element to be the sum of the elements from the input arrays. For example, if the two input
arrays are [3, 5, 2, 6, 4, 9] and [1, 2, 3, 4, 5, 6], the returned sum array should be [4, 7, 5, 10,
9, 15].
4. Write a method to display an int array's contents on the console window. The header of the
method is as below.
public static void displayArray (int[] list)
5. Write the main method to:
a. Create two input arrays with the same size by invoking the inputArray method twice
in the main method.
b. Calculate the average of the first int array by invoking the average method. Display
the average result on the console window.
c. Calculate the array sum of both input arrays by invoking the add method.
d. Display the sum array by invoking the displayArray method.
Transcribed Image Text:1. Write a method that returns an int array using user's inputs from the console window. The method should have the following header. The formal parameter size is the size of the return array. public static int[] inputArray (int size) 2. Write a method that calculates and returns the average of an array with the following headers. public static double average (int[] list) 3. Write a method to add two int arrays, assuming that arrays referred by variables a and b are of the same size. The header of the method is as follows. public static int[] add (int[] list1, int[] list2) The add method should return an array of the same size as the input arrays, with each element to be the sum of the elements from the input arrays. For example, if the two input arrays are [3, 5, 2, 6, 4, 9] and [1, 2, 3, 4, 5, 6], the returned sum array should be [4, 7, 5, 10, 9, 15]. 4. Write a method to display an int array's contents on the console window. The header of the method is as below. public static void displayArray (int[] list) 5. Write the main method to: a. Create two input arrays with the same size by invoking the inputArray method twice in the main method. b. Calculate the average of the first int array by invoking the average method. Display the average result on the console window. c. Calculate the array sum of both input arrays by invoking the add method. d. Display the sum array by invoking the displayArray method.
public static void main(String[] args) {
int[] arr1 = inputArray (?); // Enter any input array size for testing
int[] arr2 = inputArray (?); // Enter the same input array size for
// testing
//Prints the average of the elements in the first array.
System.out.println("The average of the first array provided is "
/*Please write your code here*/ + "-");
//Creates an array that holds the value of the sums from adding the two
//integer arrays.
int[] resultingArray = add(arr1, arr2);
//Prints the array with the sum of the two added integer arrays.
displayArray (resultingArray);
}
public static int[] inputArray (int size) {
//Creates an array of size provided.
int[] inputArr = new int [size];
//Asks user to input values for elements to be.
System.out.println("Enter" + size + "integer values to add to the
array.");
//Please write your code here
}
public static double average (int[] list) {
//Please write your code here
}
public static int[] add(int[] listi, int[] list2) {
//Please write your code here
}
public static void display Array(int[] list) {
System.out.println("The sum resulting array is " +
/*Please write your code here*/);
}
Finally, your code's formatting should look exactly like the output mentioned below and
should be able to run test cases on different values of 'size'.
Enter 8 integer values to add to the array.
1 2 3 4 5 6 7 8
Enter 8 integer values to add to the array.
3 5 7 9 2 4 6 1
The average of the first array provided is 4.5.
The sum resulting array is [4, 7, 10, 13, 7, 10, 13, 9]
Transcribed Image Text:public static void main(String[] args) { int[] arr1 = inputArray (?); // Enter any input array size for testing int[] arr2 = inputArray (?); // Enter the same input array size for // testing //Prints the average of the elements in the first array. System.out.println("The average of the first array provided is " /*Please write your code here*/ + "-"); //Creates an array that holds the value of the sums from adding the two //integer arrays. int[] resultingArray = add(arr1, arr2); //Prints the array with the sum of the two added integer arrays. displayArray (resultingArray); } public static int[] inputArray (int size) { //Creates an array of size provided. int[] inputArr = new int [size]; //Asks user to input values for elements to be. System.out.println("Enter" + size + "integer values to add to the array."); //Please write your code here } public static double average (int[] list) { //Please write your code here } public static int[] add(int[] listi, int[] list2) { //Please write your code here } public static void display Array(int[] list) { System.out.println("The sum resulting array is " + /*Please write your code here*/); } Finally, your code's formatting should look exactly like the output mentioned below and should be able to run test cases on different values of 'size'. Enter 8 integer values to add to the array. 1 2 3 4 5 6 7 8 Enter 8 integer values to add to the array. 3 5 7 9 2 4 6 1 The average of the first array provided is 4.5. The sum resulting array is [4, 7, 10, 13, 7, 10, 13, 9]
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

The last part of the code is not completed. 

public static void displayArray(int[] list)

{

System.out.println("The sum resulting array is" + Arrays.toString(list));

}

}

 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Passing Array as Argument
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,