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

Java programming: Write a program called Distribution that reads a file of doubl

ID: 3754536 • Letter: J

Question

Java programming:

Write a program called Distribution that reads a file of double values into an array and computes and prints the percentage of those numbers within 1 standard deviation (SD), within 2 SDs, and within 3 SDs of the mean.

The program should be modular and should at least contain the main method and a method for computing the above percentages given the numbers, the mean, and the standard deviation. Other required statistics should be computed in their own methods.

Explanation / Answer

import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Distribution { public static void main(String args[]){ Scanner scan; //arraylist of type double List input = new ArrayList(); try{ // Please enter the path of the file name you are trying // to read double values. File file = new File("yourfilename/data.txt"); scan = new Scanner(System.in); // Reading the double values from input file and storing in arraylist of type double while(scan.hasNextDouble()){ double d = scan.nextDouble(); input.add(d); } // Percentage of numbers within 1st SD double standarddeviation1 = calculateStandardDeviation(input); System.out.println("Standard deviation of numbers is " + standarddeviation1); double percentagewithSD1 = (calculatenumberswithinSD(input,standarddeviation1) / input.size()) * 100; System.out.println("Percentage of numbers below Standard deviation 1 is " + percentagewithSD1); // Percentage of numbers within 2nd SD ==> 2 times SD double standarddeviation2 = 2 * calculateStandardDeviation(input); System.out.println("Standard deviation of numbers in 2 SDis " + standarddeviation2); double percentagewithSD2 = (calculatenumberswithinSD(input,standarddeviation2) / input.size()) * 100; System.out.println("Percentage of numbers below within 2 Standard Deviation is " + percentagewithSD2); // Percentage of numbers within 3rd SD ==> 3 times SD double standarddeviation3 = 3 * calculateStandardDeviation(input); System.out.println("Standard deviation of numbers within 3 SDs of mean" + standarddeviation3); double percentagewithSD3 = (calculatenumberswithinSD(input,standarddeviation3) / input.size()) * 100; System.out.println("Percentage of numbers below within 3 Standard Deviation of mean is " + percentagewithSD3); } catch (Exception e1) { e1.printStackTrace(); } } public static double calculateStandardDeviation(List dot){ double total = 0.0, standardDeviation = 0.0; int length = dot.size(); for(double num : dot) { total += num; } //Calculating the average double mean = total/length; for(double num: dot) { standardDeviation += Math.pow(num - mean, 2); } //returning the standard deviation return Math.sqrt(standardDeviation/length); } //Generic method to calculate the number of array elements below the standard deviation public static int calculatenumberswithinSD(List input,double standarddeviation){ int totalnumbersbelowstandarddeviation=0; for(double num1: input) { if(num1
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