Design and implement a Java program that will read a file containing numbers and
ID: 440710 • Letter: D
Question
Design and implement a Java program that will read a file containing numbers and compute the following statistics: the range (low, high), the average and the median (middle number). Notes: - the first number in the input file will be the number of numbers in the file - the maximum number of numbers in the file will be 1000 - to find the median you must first sort the numbers - algorithms/code for inputting/outputting arrays, sorting arrays were covered in class and are in the text Your program must contain at least the following methods: - main - for driving the other methods - getdataExplanation / Answer
import java.io.*; class NumbersFile { public static void main(String[] args) throws Exception { BufferedReader br=new BufferedReader(new FileReader("numbers.txt")); LineNumberReader reader = new LineNumberReader(new FileReader("numbers.txt")); int data = reader.read(); int lineNumber=0; while(data != -1){ lineNumber = reader.getLineNumber(); } int array[]=new int[lineNumber]; int k=0; String st=""; while((st=br.readLine())!=null){ array[k]=Integer.parseInt(st); k++; } int low = array[0]; int high = array[0]; int sum=0; for (int i = 1; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.