Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA- Write a program that prompts the user to input 10 grades for a test. You a

ID: 3691524 • Letter: J

Question

JAVA- Write a program that prompts the user to input 10 grades for a test. You are to use a method to find the average grade for the tests and methods to find the minimum grade and maximum grade for the test. You are only required to create a main program that accepts 10 inputs from the user for the grade amounts (they must be between 0 and 100, inclusive). If the user enters an amount outside the range, they should be prompted to enter the value again. You must use an array to store the valid values the user enters. Recall that average is the sum of the values divided by the number of values. The method averageGrade() should return the average for all the values in the array. The method minGrade() should return the minimum value in the array. The method maxGrade() should return the largest value from the array.

Example of what your output should look like:

The test grades are:
87.40
99.00
91.20
88.00
87.20
87.00
89.00
65.00
44.20
99.30

The Average is: 83.73

The Minimum Grade is: 44.20

The Maximum Grade is 99.30

Explanation / Answer

public class LoopStatements

{

    // Main Method

    public static void main(String[] args)

{

        // Initialize

        int grade = 0;              // grade value

        int numberofstudents = 0;   // total number of students to be inputed

        int numberofgrades = 0;     // number of grades for student being entered

        float total = 0;            // sum of grades

// Create Scanner

        Scanner input = new Scanner(System.in);

// Prompt user to input total number of Students.

        System.out.println("Please enter the total number of Students: ");

        numberofstudents = input.nextInt();

//Set loop continuation to run for numberofstudents being entered.

        for (int i = 0; i < numberofstudents; i++) {

            // Prompt user to enter student grades.

            System.out.println("Please enter number of grades for Student: ");

            numberofgrades = input.nextInt();

//Set loop continuation to run for numberofgrades to be entered for that student.

            for (int j=0; j < numberofgrades; j++) {

                //Prompt user to enter a grade.

                System.out.println("Please enter Students' grade:");

                grade = input.nextInt();

//Initialize

                int highest = 0;            // running highest grade

                int lowest = 0;             // running lowest grade

                double average = 0;         // average of grades

//Test to see if grade is valid

                while (grade < 0 || grade > 100) {

                    System.out.println("Grade must be between 0 and 100. Please enter another grade ");

//Determine if this is highest grade so far and store for highest

                    if (grade > highest) {

                        highest = grade;

                    }

//Determine if this is lowest grade so far and store for lowest

                    if (grade < lowest) {

                        lowest = grade;

                    }

                    total += grade;

average = (total/numberofgrades);

}

System.out.println("The highest grade is " + highest);

System.out.println("The lowest grade is " + lowest);

System.out.println("The average grade is " + average);

            }

        }  

    }  

}