Answer to Question #234971 in Java | JSP | JSF for Momo

Question #234971
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.
Make use of a method to get the input from the user, another method to accumulate the student
results, a method to determine the average result and a final method to create the results report.
In your solution make provision if a user has entered in an invalid result amount. Any result
entered that is below zero (0) is an invalid entry.
1
Expert's answer
2021-09-10T18:54:19-0400
import java.util.Scanner;
public class Main
{
    public static int n;
    
    public static String module;
    public static int [] scores;
    public static void getInput(){
	    Scanner in=new Scanner(System.in);
	    System.out.println("Enter the name of the module: ");
		module=in.next();
		System.out.println("Enter the number of students: ");
		n=in.nextInt();
	}
	public static void accumulate_result(){
	    scores =new int [n];
	    int x=n;
	    Scanner in=new Scanner(System.in);
	    System.out.println("Enter the scores of the students:");
        for(int i=0;i<x;i++){
            scores[i]=in.nextInt();
        }
    }
    
    public static int average_result(){
        int avg;
        int sum=0;
        for(int i=0;i<n;i++){
            sum+=scores[i];
        }
        avg=sum/n;
        return avg;
        }
    public static void results_report(){
            System.out.println("Module name: "+module);
            System.out.println("Number of students: "+n);
            System.out.println("Average score: "+average_result());
            System.out.println("Results of the student:");
            for(int i=0;i<n;i++){
                System.out.println("Student"+(i+1)+" score: "+scores[i]);
            }
        }
	public static void main(String[] args) {
        getInput();
        accumulate_result();
        results_report();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS