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

Compute the median of data file. The median is the number that has the same numb

ID: 3760491 • Letter: C

Question

Compute the median of data file. The median is the number that has the same number of data elements greater than the numbers as there are less than the number. For purposes of this problem, you are to assume that the data is sorted (that is, is in increasing order). The median is the middle element of the file if there are an odd number of elements, or the average of the two middle elements if the file has an even number of elements. You will need to open the file, count the members, close the file and calculate the location of the middle of the file, open the file again (recall the “start over” discussion in this chapter], count up to the file entries you need, and calculate the middle. While testing construct several files on your own, including one with an even number of data points, increasing, and one with an odd number, also increasing. When you are confident your program is correct, modify it to read data from a file called dataMedianQuartiles

Explanation / Answer

first program:

second Program:

import java.util.Scanner;
import java.io.IOException;
import java.io.File;
import java.io.PrintWriter;

public class Array {

Scanner keyboard = new Scanner(System.in);

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

File myFile = new File("dataMedianQuartiles.txt");
Scanner inputFile = new Scanner(myFile);

int[] mynumFile = new int[4];
int i = 0;
double median;
double sum = 0;
int middle;

while (inputFile.hasNextInt())
{

mynumFile[i] = inputFile.nextInt();
sum += mynumFile[i];
i++;


System.out.println(numFile);

}

middle = (mynumFile.length)/2;

median = (mynumFile[middle-1] + mynumFile[middle]) / 2.0;

System.out.println("Median number is: " + median);
  

inputFile.close();

}

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