Design a Java application that will allow a user to capture the top students for a module. Allow the
user to enter in the module name, followed by the number of students the user would like to
capture.
Continue to capture the results for the number of students entered. Once all the student results
have been captured create a results report.
In the results report display the student results entered, a student count and the average result
obtained.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Module name: ");
String moduleName = in.nextLine();
System.out.print("Number of students: ");
int numberOfStudents = in.nextInt();
double[] results = new double[numberOfStudents];
double total = 0;
for (int i = 0; i < results.length; i++) {
System.out.print("Student " + (i + 1) + ": ");
results[i] = in.nextDouble();
total += results[i];
}
System.out.println("\nREPORT");
System.out.println(moduleName + "(Students: " + results.length + ")");
for (int i = 0; i < results.length; i++) {
System.out.println(results[i]);
}
System.out.printf("Average: %.2f\n", total / results.length);
}
}
Comments
Leave a comment