Java project
Page 1 of 3
Programming Project 7 (Due on 4-26-2016 at 4:00 PM)
Write a JAVA program to solve the following problem. Your program should properly
compile and run and is well documented. You need to upload into Moodle the following:
The electronic version of your SINGLE source code file after you successfully
compiled and ran it. Please label your file appropriately.
Very Important Note: Do NOT upload any other files into Moodle; just ONE file
with the extension “.java” that is it.
1. Write a Java program that computes and outputs the mean and the standard deviation of a set
of double values that are stored in an input file called “inputValues.txt”. The number of
double values, n, is stored as the first data item in the file then the actual data values follow.
A sample data file that you MUST use to test your program is posted below the
assignment link. Do NOT change the input file name; just use “inputValues.txt”. The
formula for the standard deviation is given below where x’ is the mean.
1
' 1
2
n
xx SD
n
i i
The summation symbol, , can be expanded as follows: (x1- x’)* (x1- x’) + (x2- x’) * (x2- x’)
+ …….+(xn- x’) * (xn - x’). Your output should be labeled clearly and formatted neatly, see
the given snapshots. Floating point outputs should be displayed using two decimal points.
The algorithm that your program should implement can be briefly described as follows:
The program will read the data items from the file only once and store them in a double
array defined to hold these numbers. Hint: Make sure you check how to read data from
text-based files discussed in section 7.1 of your textbook.
Given that your program is dealing with input files, you need to either declare your main()
method so that it throws FileNotFoundException or you use a try-catch block around the
code that open and access the file, check chapter 7 for details.
You need to instantiate the double array right after you know the required size (once you
read the first data item from the file).
Page 2 of 3
Then, use a loop to read the values from the file one at a time and store each value in one
array element. You can use this loop also to compute the overall total of all read values.
After that, you need to compute the mean value.
The main method will then call another method, ComputeSD(), and pass to it the array
and the mean value. The ComputeSD() method will use a loop to access the elements of
that array in order to compute and return the standard deviation to the main() method. The
head of this method is given below.
“public static double ComputeSD(double [] dataArray, double mean)”
In addition, your main() method must find the largest and smallest values in the read
data items and display them on the screen. Hint, to find the largest number, store the
first array element in a temporary variable then, in a loop, compare this element with every
other elements of the array. If the current array element is larger than the temporary
variable just store the array element into the temporary variable and keep looping. At the
end of the loop, the temporary variable will have the largest value in the array.
You can use a similar procedure to find the smallest value. You may also consult
common array algorithms examples discussed in section 6.3 of your textbook.
Snapshots for the desired output are given below. Your output should look like them.
A snapshot of the output that shows the computed mean, SD, min and max.
Page 3 of 3
A snapshot of the output that shows the exception happened when the input file cannot
be found. Make sure you type the complete name of the input file including the extension
as shown in the first snapshot.
(End of Project)