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

1. Create, using NetBeans, a complete Java program called CalcWeightedAvg accord

ID: 3664267 • Letter: 1

Question

1. Create, using NetBeans, a complete Java program called CalcWeightedAvg according to the following guidelines.

The input values come from a single line in a text le such as the following: 0.5 70 80 90 10
0.30 80 90 0 100
0.1 50 60 50 70

The output le should look something like this:

“When using the data 0.5 70 80 90 10 (where 0.5 is the weight, and the average is computed after dropping the lowest of the rest of the values.) the weighted average is 40.

When using the data 0.3 80 90 0 100 (where 0.3 is the weight, and the average is computed after dropping the lowest of the rest of the values.) the weighted average is 30.

When using the data 0.1 50 60 50 70 (where 0.1 is the weight, and the average is computed after dropping the lowest of the rest of the values.) the weighted average is 6.”

Thoughts:
*) You'll need to modify your methods to handle three lines of data instead of just one.

Explanation / Answer

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;


public class CalcWeightedAvg {

    public static void main(String[] args) throws IOException {

String line;
        FileReader fr=new FileReader("/home/shekhar/Desktop/chegg/CalcWeightedAvgData");
        BufferedReader br=new BufferedReader(fr);
        line=br.readLine();
        String[] intVal=new String[5];
int [] intarr = new int[5];
        while(line!=null)
        {
            System.out.println(line);
        line=br.readLine();
    intVal=line.split(line, ' ');
    float n=Integer.parseInt(intVal[0]);
    intarr[0]=Integer.parseInt(intVal[1]);
    intarr[1]=Integer.parseInt(intVal[2]);
    intarr[2]=Integer.parseInt(intVal[3]);
    intarr[3]=Integer.parseInt(intVal[4]);
Arrays.sort(intarr);
int sum=0;
for (int i = intarr.length-1; i >0 ;i--) {
    sum=sum+intarr[i];
}
System.out.println("The weighted Average is"+sum/n);
        }
        fr.close();       
    }

}