Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Average an array) Write two overloaded methods that return the average of an ar

ID: 3811098 • Letter: #

Question

(Average an array) Write two overloaded methods that return the average of an array with the following headers:

       public static int average(int [] array)

       public static double average(double[] array)

Write a test program that prompts the user to enter to double values, invokes the method and displays the average value.

(Average an array) Write two overloaded methods that return the average of an array with the following headers:

       public static int average(int [] array)

       public static double average(double[] array)

Write a test program that prompts the user to enter to double values, invokes the method and displays the average value.

Replicate the following output:

Sample Run for Exercise07 08 Enter input data for the program Sample data provided below. You may modify it.) 1.7 89.2 3.5 2.2 1.2 6.3 4.3 21.4 5 1 2.5 TINY NEBULA] Watercolor Painting Show the Sample Output Using the Preceeding Input command java Exercisee7 08 Enter 10 double values: 1.7 89.2 3.5 2.2 1.2 6.3 4.3 21.4 5.1 2.5 The average value is 13.74 command

Explanation / Answer

AverageTest.java

package test5;

import java.util.Scanner;

public class AverageTest {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
           double array[] = new double[10];
           System.out.print("Enter 10 double values: ");
           for(int i=0;i< array.length; i++){
               array[i] = scan.nextDouble();
           }
           System.out.println("The average value is "+average(array));
   }
   public static double average(double array[]){
       double sum = 0;
       double avg = 0;
       for(int i=0; i<array.length; i++){
           sum = sum + array[i];
       }
       avg = sum/array.length;
       return avg;
   }
   public static double average(int array[]){
       double sum = 0;
       double avg = 0;
       for(int i=0; i<array.length; i++){
           sum = sum + array[i];
       }
       avg = sum/array.length;
       return avg;
   }
  
}

Output:

Enter 10 double values: 1.7 89.2 3.5 2.2 1.2 6.3 4.3 21.4 5.1 2.5
The average value is 13.74