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

In the window below are several FDME comments. They describe what to do. For exa

ID: 3779844 • Letter: I

Question

In the window below are several FDME comments. They describe what to do. For example, if the statement indicates "...calls myMethod passing quakes as a parameter" then you know that portion will look something like myMethod(quakes); Recall that method calls come in two forms: those that are a statement in and of themselves, and those that return something that will be assigned to a variable. Here is the class outline structure: main() declares numlnputs and reads in a valpe from the user +prints "numlnputs is n', where n is the user input calls the three methods below initArray() prints "Using a random number generator to initialize array with n elements where n is the int value passed into init0 +prints "Returning array" get stats +prints "In getStats' +declares variable for the min, max average and range then prints out their initial values. print prints "In print" Sample output When input is The output exactly matches when input is 5 numInputs is 5 Using a random number generator to initialize array with 5 elements Returning array In get stats Maximum 0.0 Minimum: 0.0 Average 1 0.0 Range 0 In print

Explanation / Answer

import java.util.Scanner;
import java.util.Random;
public class Lab7a{

   public static void main(String[] args){
       Scanner scnr = new Scanner(System.in);
       Random rand = new Random(107L);
       int numInputs = scnr.nextInt();
       System.out.println("numInputs is "+numInputs);
       double number[]= initArray(numInputs,rand);
       getStats(number);
       print();
   }
   public static double[] initArray(int n,Random rand){
       double arr[] = new double[n];
       System.out.println("Using a random number generator to initialize array with "+n+" elements");
       for(int i=0;i<n;i++){
           arr[i] = rand.nextDouble();
           System.out.print(arr[i]+" ");
       }
       System.out.println(" Returing array");
       return arr;
   }
   public static void getStats(double arr[]){
       System.out.println("In getStats");
       double min=arr[0];
       double max=arr[0];
       double average=arr[0];
       int range = arr.length;
       for(int i=1;i<range;i++){
           if(min>arr[i])
               min = arr[i];
           if(max<arr[i])
               max = arr[i];
           average += arr[i];
       }
       System.out.println("Maximum:"+max);
       System.out.println("Minimum:"+min);
       System.out.println("Average:"+(average/range));
       System.out.println("Range:"+range);
   }
   public static void print(){
       System.out.println("In print");
   }
}
/*
sample output

5
numInputs is 5
Using a random number generator to initialize array with 5 elements
0.7217409095430285 0.7036092299086912 0.3780518354339377 0.12528099013345873 0.7292394711024991
Returing array
In getStats
Maximum:0.7292394711024991
Minimum:0.12528099013345873
Average:0.531584487224323
Range:5
In print
*/