i need help building off of a previous program i submitted I
i need help building off of a previous program i submitted. I can\'t seem to figure out how to complete the below assignment. I will post my current code beneath the assignment.
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.
Thoughts
Consider importing java.util.Arrays and using the sort method on your array of numbers.
my current code is here
package calcavgdroplowest;
import java.text.DecimalFormat;
 import java.util.Scanner;
public class CalcAvgDropLowest {
static int size;
 public static void main(String[] args) {
 
 
 
   
 Scanner input=new Scanner(System.in);
   
 size=5;
   
 double[] array=new double[size];
   
 array=ArrayToDoubles();
   
 double avg=ShowAverage(array);
   
 Result(array, avg);
 
 int n=0;
 }
 public static int readSmallestNumberOfNumbers() {
 Scanner scanner = new Scanner(System.in);
 int n = 0;
 System.out
 .print(\"Enter the number of numbers to drop before calculating the average:\");
 n = scanner.nextInt();
 return n;
 }
 public static double[] ArrayToDoubles(){
 Scanner input=new Scanner(System.in);
 double[] array=new double[size];
   
 System.out.println(\"\  Please enter \"+size+\" numbers you wish to calculate separated by space: \");
 for(int i=0;i<size;i++){
 array[i]=input.nextDouble();
 }
 return array;
 }
   
 public static double ShowAverage(double[] doublearray){
 double avg=0;
 double sum=0;
 
 for(int i=0;i<size;i++){
 sum=sum+doublearray[i];
 }
   
 
 avg=sum/size;
 return avg;
   
 
 }
 public static void Result(double[] array,double value) {
 
 DecimalFormat df=new DecimalFormat(\"#.00\");
 System.out.print(\"\ The average of the numbers \");
   
 
 for(int i=0;i<size;i++){
 
 System.out.print(\" \"+df.format((array[i])));
 if(i==size-2)
 {
 System.out.print(\" and \");
 }
 else
 {
 System.out.print(\",\");
 }
 
 }
 System.out.print(\" is \"+df.format((value))+\".\");
 }
}
Solution
CalAvgDropLowest.java
import java.text.DecimalFormat;
 import java.util.Arrays;
 import java.util.Scanner;
public class CalAvgDropLowest {
    //Declaring static variables
    static Scanner sc=null;
   
    //Declaring constant
    public static final int SIZE=10;
    public static void main(String[] args) {
       
        //Declaring variables
        int n;
        double average=0.0;
       
        //Creating an double array based on the constant SIZE
    double arr[]=new double[SIZE];
   
    //Scanner class object is sued to read the inputs entered by the user
    sc=new Scanner(System.in);
   
    //Calling the method which will get the numbers entered by the user
    arr=getTheNumbers();
   
    //calling the method which will get the number entered by the suer
    n=numOfLowestTermsTodrop();
   
    //Calling the method which will calculate the average
    average=calAvg(arr,n);
   
    //Calling the method which will display the results on the console
    displayResults(arr,n,average);
   
    }
   /* This method will display the results on the console
    * Params :double array,number of type integer,average of type double
    * Return :void
    */
    private static void displayResults(double[] arr, int n, double average) {
        DecimalFormat df=new DecimalFormat(\"#.##\");
        System.out.print(\"\ Given the numbers \");
        for(int i=0;i<SIZE;i++)
        {
        System.out.print(arr[i]+\", \");  
        }
        System.out.print(\"\ the average of all the numbers except the lowest \"+n+\" numbers is \"+df.format(average));
       
       
    }
   /* This method will calculate the average of the numbers by leaving the lowest number of numbers
    * Params :double array,number of type integer
    * Return :average of type double
    */
    private static double calAvg(double[] arr, int n) {
       
        //Sorting the double type array in ascending order
        Arrays.sort(arr);
       
        //Declaring local variables
        double sum=0.0,avg=0.0;
       
        //This for loop will calculate the sum of array elements by leaving the no of lower numbers
        for(int i=n;i<SIZE;i++)
        {
            //calculating the sum
            sum+=arr[i];
        }
       
        //calculating the average
        avg=sum/(SIZE-n);
       
        return avg;
    }
   /* This method will get how many lower elements have to leave from the user
    * Params :void
    * Return :number of type int
    */
    private static int numOfLowestTermsTodrop() {
       
        //Declaring the local variable
        int n;
       
        //Getting the number entered by the user
        System.out.print(\"\ Enter the number of lowest terms to drop :\");
        n=sc.nextInt();
        return n;
    }
   /* This number will get numbers entered by the user and populating them into an array
    * params:void
    * return:double ype array
    */
    private static double[] getTheNumbers() {
       
        //Creating an double type array based on the size
        double arr[]=new double[SIZE];
       
        //Getting the numbers entered by the user
        System.out.print(\"Enter 10 numbers in one line :\");
        for(int i=0;i<SIZE;i++)
        {
            //Populating the numbers into an array
            arr[i]=sc.nextDouble();
        }
        return arr;
    }
}
________________________________________
Output:
Enter 10 numbers in one line :30 50 40 60 70 80 90 100 10 20
Enter the number of lowest terms to drop :3
Given the numbers 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0,
 the average of all the numbers except the lowest 3 numbers is 70
__________________Thank You





