Question: I built this code, but it still says that my output is wrong, and I have no idea how to fix it. 1.Ensure the file

I built this code, but it still says that my output is wrong, and I have no idea how to fix it.

1.Ensure the file named BattingAverage.java is open.

Write the Java statements as indicated by the comments.

Execute the program by clicking "Run Code." Enter the following batting averages: .299, .157, .242, .203, .198, .333, .270, .190. The minimum batting average should be .157, and the maximum batting average should be .333. The average should be .2365.

import java.util.Scanner;

public class BattingAverage {

public static void main(String args[]) {

Scanner s = new Scanner(System.in);

final int ARRAY_SIZE = 8;

double[] averages = new double[ARRAY_SIZE];

int loopIndex;

double battingAverage;

String averageString;

double min, max;

double total, average;

for (loopIndex = 0; loopIndex < ARRAY_SIZE; loopIndex++) {

System.out.println("Enter a batting average: ");

averageString = s.nextLine();

battingAverage = Double.parseDouble(averageString);

averages[loopIndex] = battingAverage;

}

min = averages[0];

max = averages[0];

total = averages[0];

for (loopIndex = 1; loopIndex < ARRAY_SIZE; loopIndex++) {

double currentAverage = averages[loopIndex];

total += currentAverage;

if (currentAverage < min) {

min = currentAverage;

}

if (currentAverage > max) {

max = currentAverage;

}

}

average = total / ARRAY_SIZE;

System.out.print("Averages entered: ");

for (loopIndex = 0; loopIndex < ARRAY_SIZE; loopIndex++) {

System.out.print(averages[loopIndex] + " ");

}

System.out.println();

System.out.printf("Minimum: %.3f ", min);

System.out.printf("Maximum: %.3f ", max);

System.out.printf("Average: %.4f ", average);

System.exit(0);

}

}

Results:

Minimum batting average is 0.157

Maximum batting average is 0.333

Average batting average is 0.270

Expected Output:

Minimum batting average is 0.157

Maximum batting average is 0.333

Average batting average is 0.270

0

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!