Write a java program to solve the following problem: You have N students in a class. You want a java program that

  • برمجة جافا

Exercise 8 (Students grade book): Write a java program to solve the following problem:

 

You have N students in a class. You want a java program that allows the user to enter the number of students in the class and then the final grade (out of 100%) for each student. Then, the program should calculate and print the following statistics about students’ grades:

The number of pass students

The number of failed students

The number of students who got the grade excellent (>= 90)

The number of students who got the grade very good (>= 80)

The number of students who got the grade Good (>= 70)

The number of students who got the grade Acceptance (>= 60)

The Highest Students’ Grade

The Lowest Students’ Grade

 

الأجوبة

import java.util.Scanner;
public class Main
{
	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];
	    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++)
	    {
	        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);
	        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);
	}
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...