Q:

Re-write the java program in exercise 8 by developing a method called “StudentsGradesStatistics” and passing the array that contains the students grades to the method that will calculate and print all statistics

0

Exercise 10: Re-write the java program in exercise 8 by developing a method called “StudentsGradesStatistics” and passing the array that contains the students grades to the method that will calculate and print all statistics. In the main, you have to declare the array, insert students number and grades, and then call the method that takes the array as a parameter.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class HelloWorld
{
	public static void main(String[] args) {
	    Scanner input=new Scanner(System.in);
	    System.out.println("enter the number of students:");
	    int numberofStudents=input.nextInt();
	    int []grades=new int[numberofStudents];
	    for(int i=0;i<grades.length;i++)
	    {
	        do{
	        System.out.println("enter grade of student "+(i+1));
	        grades[i]=input.nextInt();
	        if(grades[i]>100 || grades[i]<0)
	        System.out.println("invlid grade, it should be between 0 to 100");
	        }
	        while(grades[i]>100 || grades[i]<0);
	        
	    }
	    StudentsGradesStatistics(grades);
	}
	
	public static void StudentsGradesStatistics(int grades[])
	{
	    int numOfPassStudents=0,numOfFailStudents=0,numOfExcelentStudents=0,numOfVeryGoodStudents=0,numOfGoodStudents=0,numOfAcceptanceStudents=0;
	    int highestGrade=-1,lowestGrade=101;
	    for(int i=0;i<grades.length;i++)
	    {
	        if(grades[i]>=60)
	        {
	            numOfPassStudents++;
	            if(grades[i]>=90)
	            numOfExcelentStudents++;
	            else if(grades[i]>=80)
	            numOfVeryGoodStudents++;
	            else if(grades[i]>=70)
	            numOfGoodStudents++;
	            else numOfAcceptanceStudents++;
	            
	        }
	        else
	        numOfFailStudents++;
	        
	        if(grades[i]>highestGrade)
	        highestGrade=grades[i];
	        if(grades[i]<lowestGrade)
	        lowestGrade=grades[i];
	    }
	    
	    System.out.println("number of passed students: "+numOfPassStudents);
	    System.out.println("number of failed students: "+numOfFailStudents);
	    System.out.println("number of excelent students: "+numOfExcelentStudents);
	    System.out.println("number of very good students: "+numOfVeryGoodStudents);
	    System.out.println("number of good students: "+numOfGoodStudents);
	    System.out.println("number of acceptance students: "+numOfAcceptanceStudents);
	    System.out.println("highest grade: "+highestGrade);
	    System.out.println("lowest grade: "+lowestGrade);
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now