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

my problem is in the last part of the program i can\'t get the grades entered in

ID: 3641113 • Letter: M

Question

my problem is in the last part of the program i can't get the grades entered in the array to print.

import javax.swing.JOptionPane;
public class Average{
public static void main(String[] args) {
String input, amount;
double data[];
int total;
double sum = 0, average = 0;

System.out.println(" Average Program");
amount = JOptionPane.showInputDialog("Enter Total Number of grades to enter");
total = Integer.parseInt(amount);
data = new double[total];

for (int i = 0; i < data.length; i++) {
input = JOptionPane.showInputDialog("Enter Your grades");
data[i] = Double.parseDouble(input);
}
for (int i = 0; i < data.length; i++) {
sum += data[i];
average = sum / data.length;
}
JOptionPane.showMessageDialog(null, "The Grades entered are: " + data[]
+ " The Average is: " + average, "Result",
JOptionPane.INFORMATION_MESSAGE);

}
}

Explanation / Answer

import java.text.DecimalFormat;
import javax.swing.JOptionPane;

public class Average {
    public static void main(String[] args) {
        String input, amount;
        double data[];
        int total;
        double sum = 0, average = 0;
        String gradesReport;
        DecimalFormat gradeFormat = new DecimalFormat("#.00");

        System.out.println(" Average Program");
        amount = JOptionPane.showInputDialog("Enter Total Number of grades to enter");
        total = Integer.parseInt(amount);
        data = new double[total];

        for(int i = 0; i < data.length; i++) {
            input = JOptionPane.showInputDialog("Enter Your grades");
            data[i] = Double.parseDouble(input);
        }
        for (int i = 0; i < data.length; i++) {
            sum += data[i];
            average = sum / data.length;
        }
      
        gradesReport = "The Grades entered are: ";
        for (int i = 0; i < data.length; i++) {
            gradesReport += gradeFormat.format(data[i]) + " ";
        }
        gradesReport += " The Average is: " + gradeFormat.format(average);
      
        JOptionPane.showMessageDialog(null, gradesReport,
                "Result", JOptionPane.INFORMATION_MESSAGE);

    }
}

(Red: optional)