This solution must be one java file not multiples This solut
This solution must be one java file not multiples.
This solution also needs proper java formatting.
Create, using NetBeans, a complete Java program called CalcAvgDropLowest according to the following guidelines.
The program prompts the user for five to ten numbers all on one line, separated by spaces, calculates the average of all those numbers except the lowest n numbers, where n is given by the user, and displays all the numbers and the calculated average to the user.
The program uses methods to:
get the numbers used to calculate the average;
get the number of lowest numbers to drop before calculating the average
calculate the average of the numbers (except the lowest n numbers) entered by the user; and
print the results.
The first method should take no arguments and return an array of doubles.
The second method should take no arguments and return a single integer, the number of the lowest numbers to drop before calculating the average.
The third method should take an array of doubles (the return value of the first method above) and a single integer value (the number of lowest items to drop before calculating the average) and return a double (the average of all the numbers except the lowest n values).
The fourth method should take an array of doubles, an integer, and a double as arguments but have no return value.
For example:
If the user gives these numbers for calculating the average:
40 60 80 100 20
and the user gives the number 2 to indicate how many of the lowest values should be dropped before calculating the average, then
the program should give as output:
Given the numbers 40.00, 60.00, 80.00, 100.00, and 20.00, the average of all the numbers except the lowest 2 numbers is 80.00.
Solution
//Tested on eclipse on ubuntu,Linux
/********************CalcAvgDropLowest.java**************/
import java.util.Arrays;
import java.util.Scanner;
public class CalcAvgDropLowest {
public static void main(String[] args) {
/* Scanner class for taking input from user */
Scanner input = new Scanner(System.in);
int len = args.length;
/*
* checking length of provided numbers must be greater then or equal to
* 5 or less then 10
*/
if (len >= 5 && len <= 10) {
double[] numbers = new double[len];
/* Prompt for lowest numbers dropped before avg calculation */
System.out.println(\"How many of the lowest values should be dropped before calculating the average\");
int n = input.nextInt();
System.out.print(\"Given the numbers \");
/* Inserting element into numbers array */
for (int i = 0; i < len; i++) {
numbers[i] = Double.parseDouble(args[i]);
System.out.print(numbers[i] + \" \");
}
/* Sorting array usng sort method of Arrays class */
Arrays.sort(numbers);
double sum = 0.0;
/* not including first n number in avg calculation */
for (int i = 0; i < len; i++) {
if (i >= n) {
sum += numbers[i];
}
}
System.out.println(
\"The average of all the numbers except the lowest \" + n + \" numbers is \" + (sum / (len - n)));
} else {
System.out.println(\"Please provide total numbers 5 to 10\");
}
}
}
/***********output**************/
anshu@anshu:~/Desktop/chegg$ javac CalcAvgDropLowest.java
anshu@anshu:~/Desktop/chegg$ java CalcAvgDropLowest 40 60 80 100 20
How many of the lowest values should be dropped before calculating the average
2
Given the numbers 40.0 60.0 80.0 100.0 20.0 The average of all the numbers except the lowest 2 numbers is 80.0
Thanks a lot

