Question: Complete the code in the TODO steps within /* * The program is to read a certain number of real values, * get the average

Complete the code in the TODO steps within

/* * The program is to read a certain number of real values, * get the average of these items, and find the number * of the items that is greater than the average. * * Define the three methods that are called in the main method. * The headers of the methods are given below the main method. * You need to complete the method body. */

public class AnalyzeNumbers { public static void main(String[] args) { //PLEASE DO NOT CHANGE ANYTHING IN THE MAIN METHOD!!!!!!!!!!!!!! //create an array with user specified dimention and values double[] numbers = initArrayFromUserInputs();

//get the average of the values in numbers double average = getAverage(numbers);

// get the numbers of elements above average int count1 = countAboveValue(numbers, average); int count2 = numbers.length - count1; //The numbers of elements at or below average System.out.println("Average is " + average); System.out.println("Number of elements above the average is " + count1); System.out.println("Number of elements at or below the average is " + count2); } //end of main /* * Method nitArrayFromUserInputs: * The method will prompt user to enter the number of real values * the user wants to analyze, read the real values, store them in * an array, and finally return the array. */ public static double[] initArrayFromUserInputs() { java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter the number of values to analyze: "); int numValues = input.nextInt(); //create an array with capacity numValues double[] values = new double[numValues]; System.out.print("Enter the numbers: "); // TODO1: Write a for loop below to read numValues double values, // store them in array values. return values; } //end of nitArrayFromUserInputs /* * Method getAverage: * Given a double array, return the average of the values in the array. */ public static double getAverage(double[] nums) { // TODO2: Change the default body below to a real implementation. return 0.0; } //end of getAverage /* * Method countAboveValue: * Given a double array and a double value, return count of numbers in * the array that is above the given value. */ public static int countAboveValue(double[] nums, double value) { // TODO3: Change the default body below to a real implementation. return 0; } //end of countAboveValue }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!