Write a program to calculate the average (format to 2 decimal points) of a set of data, also find max and min values of data. All the data are stored in a file (file name would be data.txt). The 1st number in the file is the total number (N, integer) of data; the rest data in the file are N real numbers. The program MUST have the following three methods,  A method named findAvg that calculates the average of the data. public static double findAvg (double[ ] arr) //input to the method is the an 1D array //output of the method is the average. A method named findMaxMin that finds the max and min values of the data. public static double[ ] findMaxMin (double[ ] arr) //input to the method is the an 1D array //output of the method is 1D array with two values, 1st one is max value, 2nd one is min value. A method named printData that print the data, the average, the max value, and the min value. public static void printData(double[ ] arr, double avg , double[ ] MaxMin) //input to the method are an 1D array of the data, average, 1D array with max and min values Hint: You also need to use Scanner, FileInputStream, and IOException classes. Here is an example of the content in a data file ( 5 real numbers): 5 85.5 72 64.5 160.5 88.91 Here is an example of output Enter the file name: The file name is data.txt The data in the file are 85.5 72.0 64.5 160.5 88.91 The average is 94.28 The max and min values are 160.5 and 64.5

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter13: File Input And Output
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

Write a program to calculate the average (format to 2 decimal points) of a set of data, also find max and min values of data.

All the data are stored in a file (file name would be data.txt).
The 1st number in the file is the total number (N, integer) of data; the rest data in the file are N real numbers.

The program MUST have the following three methods, 
A method named findAvg that calculates the average of the data.

public static double findAvg (double[ ] arr) //input to the method is the an 1D array //output of the method is the average.
A method named findMaxMin that finds the max and min values of the data.

public static double[ ] findMaxMin (double[ ] arr) //input to the method is the an 1D array //output of the method is 1D array with two values, 1st one is max value, 2nd one is min value.

A method named printData that print the data, the average, the max value, and the min value.

public static void printData(double[ ] arr, double avg , double[ ] MaxMin) //input to the method are an 1D array of the data, average, 1D array with max and min values

Hint: You also need to use Scanner, FileInputStream, and IOException classes.

Here is an example of the content in a data file ( 5 real numbers):

5 85.5 72 64.5 160.5 88.91

Here is an example of output

Enter the file name: The file name is data.txt The data in the file are 85.5 72.0 64.5 160.5 88.91 The average is 94.28 The max and min values are 160.5 and 64.5

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning