In: Computer Science
Write a program named FinalExamProgram2 that reads numbers from a file (which you will create using Notepad) into a one-dimensional array and then analyzes the numbers as described below. Your program must use loops to read the numbers into the array and to analyze the contents of the array. The program’s main function should do the following: Read eight floating-point numbers from the file named numbers.txt into a onedimensional array, displaying each number on the screen. Pass the array to a function that finds and displays (on the screen) how many of the array’s elements are zero, how many are negative, and how many are positive. Display the number of zeroes first. Then display the other two counts in descending order. In other words, if there are more positives than negatives, display the number of positives before you display the number of negatives—and vice versa. Pass the array to another function that finds and displays (on the screen) the average of the squares of the positive numbers and the average of the squares of the negative numbers. Display these averages in descending order. Your outputs should look exactly as shown on the next page (spelling, punctuation, spacing, number format, and so on).
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// numbers.txt
34.5
-56.6
78.7
0
-11.2
34.6
0
33.3
__________________________
// FinalExamProgram2.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class FinalExamProgram2 {
public static void main(String[] args) throws
FileNotFoundException {
double nos[] = new double[8];
int i = 0;
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(new
File("numbers.txt"));
while (sc.hasNext()) {
nos[i] =
sc.nextDouble();
i++;
}
sc.close();
calculate(nos);
calcAvgSquares(nos);
}
private static void calcAvgSquares(double[] nos)
{
int pos=0,neg=0;
double
posSum=0,negSum=0,posAvg=0,negAvg=0;
for (int i = 0; i <
nos.length; i++) {
if (nos[i] < 0) {
neg++;
posSum+=nos[i]*nos[i];
} else {
pos++;
negSum+=nos[i]*nos[i];
}
}
posAvg=posSum/pos;
negAvg=negSum/neg;
if(posAvg>negAvg)
{
System.out.println("Positive
Average :"+posAvg);
System.out.println("Negative
Average :"+negAvg);
}
else
{
System.out.println("Negative
Average :"+negAvg);
System.out.println("Positive
Average :"+posAvg);
}
}
private static void calculate(double[] nos) {
int zeros = 0, positive = 0,
negative = 0;
for (int i = 0; i <
nos.length; i++) {
if (nos[i] == 0)
{
zeros++;
} else if
(nos[i] < 0) {
negative++;
} else {
positive++;
}
}
// Getting the input entered by
the user
System.out.println("No of Zeros :"
+ zeros);
if (positive > negative) {
System.out.println("No of Positives :" + positive);
System.out.println("No of Negatives :" + negative);
} else {
System.out.println("No of Negatives :" + negative);
System.out.println("No of Positives :" + positive);
}
}
}
__________________________
Output:
No of Zeros :2
No of Positives :4
No of Negatives :2
Negative Average :4844.995
Positive Average :554.8333333333334
_______________Could you plz rate me well.Thank
You