Question: Write a program and draw a flowchart in java to calculate the sum and average (format to 2 decimal points) of a set of data.

Write a program and draw a flowchart in java to calculate the sum and average (format to 2 decimal points) of a set 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, in additional to the main method :

A method named findSum that calculates the sum of the data, the header of the method should be:

public static double findSum (double[ ] )

//input to the method is an 1D array

//output is the sum of the data in the array

A method named findAvg that calculates the average of the data, the header of the method should be

 public static double findAvg (double[ ], double ) //input to the method is the an 1D array and the sum //output is the average 

A method named printData that print the data, the sum, and the average, the header of the method should be

 public static void pintData(double[ ], double, double ) //input to the method are an 1D array, sum and average 

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

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

5 85.5 72 64.5 160.5 88.9 

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 64.5 160.5 88.91 The sum is 471.41; the average is 94.28

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!