Menu

(Solved) : Lab Complete Partially Prewritten Java Program Uses Array Program Prompts User Interactive Q37288768 . . .

In this lab, you complete a partially prewritten Java programthat uses an array. The program prompts the user to interactivelyenter eight batting averages, which the program stores in an array.The program should then find the minimum and maximum battingaverage stored in the array as well as the average of the eightbatting averages. The data file provided for this lab includes theinput statement and some variable declarations. Comments areincluded in the file to help you write the remainder of theprogram. Instructions 1.Ensure the file named BattingAverage.javais open. Write the Java statements as indicated by the comments.Execute the program by clicking “Run Code.” Enter the followingbatting averages: .299, .157, .242, .203, .198, .333, .270, .190.The minimum batting average should be .157, and the maximum battingaverage should be .333. The average should be .2365. importjava.util.Scanner; public class BattingAverage { public static voidmain(String args[]) { Scanner s = new Scanner(System.in); //Declare a named constant for array size here. // Declare arrayhere. // Use this integer variable as your loop index. intloopIndex; // Use this variable to store the batting average inputby user. double battingAverage; // String version of battingaverage input by user. String averageString; // Use these variablesto store the minimim and maximum batting averages. double min, max;// Use these variables to store the total and the average. doubletotal, average; // Write a loop to get batting averages from userand assign to array. System.out.println(“Enter a batting average:”); averageString = s.nextLine(); battingAverage =Double.parseDouble(averageString); // Assign value to array. //Assign the first element in the array to be the minimum and themaximum. min = averages[0]; max = averages[0]; // Start out yourtotal with the value of the first element in the array. total =averages[0]; // Write a loop here to access array values startingwith averages[1] // Within the loop test for minimum and maximumbatting averages. // Also accumulate a total of all battingaverages. // Calculate the average of the 8 averages. // Print theaverages stored in the averages array. // Print the maximum battingaverage, minimum batting average, and average batting average.System.exit(0); } } How would i do this ?

Expert Answer


Answer to In this lab, you complete a partially prewritten Java program that uses an array. The program prompts the user to intera…

OR