asked 229k views
5 votes
Write an interactive Java Program named NestedStudentMarks WithMethodsAndParameters.java which makes use of the JOptionPane class for both input. The program should request the user to enter, first the number of students whose individual academic records need to be captured, and secondly, the number of modules the user intends to capture per student. Define a method called processMarks which accepts as parameters the number of students as well as the number of modules. The method's retum type is void. The method should capture marks for each student, implementing strictly a nested FOR loop formation. After each student's record that has been captured, that very student's Total Marks need to be displayed immediately, as well as the student's average mark over the number of modules captured for the student before the next student record is captured. At the end of each student's academic record, use System.out.printin() to display the words, "End Of Student j's Academic Record", where j is an integer, eg. End Of Student 5's Academic Record"

1 Answer

1 vote

Answer:

import javax.swing.JOptionPane;

public class NestedStudentMarksWithMethodsAndParameters {

public static void main(String[] args) {

int numStudents = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of students:"));

int numModules = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of modules:"));

processMarks(numStudents, numModules);

}

public static void processMarks(int numStudents, int numModules) {

for (int i = 1; i <= numStudents; i++) {

double totalMarks = 0;

for (int j = 1; j <= numModules; j++) {

double marks = Double.parseDouble(JOptionPane.showInputDialog("Enter marks for student " + i + " module " + j));

totalMarks += marks;

}

double averageMarks = totalMarks / numModules; // Calculate average marks for each student

System.out.println("Total Marks for Student " + i + ": " + totalMarks); // Display total marks for each student

System.out.println("Average Marks for Student " + i + ": " + averageMarks); // Display average marks for each student

System.out.println("End Of Student "+i+"'s Academic Record"); // Display end of each student's academic record

}

} // End of method processMarks()

}

answered
User Minas Petterson
by
8.3k points