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

Java program 1. Outine a program with several methods by providing \'stubs\' of

ID: 3779795 • Letter: J

Question

Java program
1. Outine a program with several methods by providing 'stubs' of those methods 2. Be abe to comple and nun the program showing its temporary output Background Reading Arrays and Methods, ZyBook, Chapters 5 and 6. in ene processat developing apogram, wechon layout general desgnbefore coding the detals in this lab you will only write an outline of your program t shoud the useful The useful part we will do n comple wthout eros but t won'tyetdoarything So why do this? You may have found by now that umping nand writing a program before you thought through what has to happen, in what ondo, and how often leads to re-wrting and/or mass cofusion. As you learn to code, eam the discoine or panning The purpose lobisto practice 'step one ,that is he and its methods Ybu wil only define variables, method method headers. The body of the methods wil have print statements that are just placeholders to show the flow of program FDOME comments. They describe what todo. For example, rthe statement indoates caus myMethod pessing quekes as a parameter then you inow that portion wil look something Ike nyMethod(qaakes) Recall that method cals come intwo forms thosethat are a statoment inandof themselves, that return somethingthat be assigned to a and those Here is the cass outine structurg: maint) declares nunminputa and reads in a value from the user prints "numinputs isn', where n is the user input +calls the three methods below initarray() prints "Using a random number generator to initialzo amay with n elements", where niste int value passed into into +prints 'Returning array" prints "in gotStata" declares variable for the min, max average and range then prints out their initial waues. When input is The output exactly matches when input is 5 nur inputs is s using a random number generator to initiali array with s elements Range

Explanation / Answer

Lab7a.java

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();
/* FIXME print numInputs here */
System.out.println("numInputs: "+numInputs);
/* FIXME declare double array called numbers and assign to it the array returned from initArray(numInputs, rand) call. */
double numbers[] = initArray(numInputs, rand);
/* FIXME Write a statement that calls getStats passing numbers as the parameter */
getStats(numbers);
/* FIXME Write a statement that calls print method passing numbers as the parameter */
print(numbers);
}
  
/* FIXME Write initArray method HEADER and BODY with a print statement and return an array here */
public static double[] initArray(int num, Random rand){
   double d[] = new double[num];
   System.out.println("Using a random number generator to initialize array with "+num+" elements");
   System.out.println("Returning array");
   return d;
}
  
/* FIXME Write getStats method HEADER and BODY with variable declarations and print statements here. */
public static void getStats(double d[]){
   double min=0, max=0, average=0, range=0;
   System.out.println("In getStats");
    System.out.println("Maximum: "+max);
   System.out.println("Minimum: "+min);
   System.out.println("Average: "+average);
   System.out.println("Range: "+range);
  
}
/* FIXME Write the print method HEADER and BODY with only a print statement here */
public static void print(double d[]){
   System.out.println("In print");
}
  
}

Output:

5
numInputs: 5
Using a random number generator to initialize array with 5 elements
Returning array
In getStats
Maximum: 0.0
Minimum: 0.0
Average: 0.0
Range: 0.0
In print

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote