Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package javaapplication 9 5 ; import java.util.Scanner; public class GradeCategorization { public static void main ( String [ ] args ) { Scanner scanner =

package javaapplication95;
import java.util.Scanner;
public class GradeCategorization {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int[][] grades = new int[3][10]; // Array to store grades for 10 students in 3 courses
// Input grades for Math
System.out.println("Enter the degree of the ten students for Math separated by space:");
for (int i =0; i <10; i++){
grades[0][i]= scanner.nextInt();
}
// Input grades for Science
System.out.println("Enter the degree of the ten students for Science separated by space:");
for (int i =0; i <10; i++){
grades[1][i]= scanner.nextInt();
}
// Input grades for English
System.out.println("Enter the degree of the ten students for English separated by space:");
for (int i =0; i <10; i++){
grades[2][i]= scanner.nextInt();
}
scanner.close();
int[][] degreeCount = new int[5][3]; // Array to count students in each degree for each course
// Categorize grades and count students in each degree for each course
for (int i =0; i <3; i++){
for (int j =0; j <10; j++){
if (grades[i][j]>=85 && grades[i][j]<=100){
degreeCount[0][i]++;
} else if (grades[i][j]>=75 && grades[i][j]<=84){
degreeCount[1][i]++;
} else if (grades[i][j]>=65 && grades[i][j]<=74){
degreeCount[2][i]++;
} else if (grades[i][j]>=50 && grades[i][j]<=64){
degreeCount[3][i]++;
} else {
degreeCount[4][i]++;
}
}
}
// Display the number of students in each degree for each course
System.out.println("| Grade | Math | Science | English |");
System.out.println("|---------|------|---------|---------|");
for (int i =0; i <5; i++){
System.out.printf("|%s |%-4d |%-7d |%-7d |
",
getGradeLabel(i),
degreeCount[i][0],
degreeCount[i][1],
degreeCount[i][2]);
}
// Calculate and display success rate in percentage for each course
int totalStudents =10;
int[] successCount = new int[3];
for (int i =0; i <3; i++){
successCount[i]= totalStudents - degreeCount[4][i]; // Total students minus F grades
}
int[] successRate = new int[3];
for (int i =0; i <3; i++){
successRate[i]=(successCount[i]*100)/ totalStudents;
}
System.out.println("| Success Rate (%)|"+ successRate[0]+"|"+ successRate[1]+"|"+ successRate[2]+"|");
}
// Helper method to get the grade label based on index
private static String getGradeLabel(int index){
switch (index){
case 0:
return "A";
case 1:
return "B";
case 2:
return "C";
case 3:
return "D";
default:
return "F";
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions