0% found this document useful (0 votes)
6 views3 pages

Grading System Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Grading System Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Scanner;

public class Grading_System {

static final int NUM_STUDENTS = 4;

static final int NUM_SUBJECTS = 5;

static String[] subjects = {"Maths", "Kiswahili", "English", "Arts", "Science"};

public static void main(String[] args) {

try (Scanner scanner = new Scanner(System.in)) {

String[] studentNames = new String[NUM_STUDENTS];

float[][] subjectMarks = new float[NUM_STUDENTS][NUM_SUBJECTS]; // Stores subject

marks

float[][] studentAverages = new float[NUM_STUDENTS][NUM_SUBJECTS];

for (int i = 0; i < NUM_STUDENTS; i++) {

System.out.println("\nEnter details for Student " + (i + 1));

// Input for student's name

System.out.print("Enter student name: ");

studentNames[i] = scanner.next();

// Loop for each subject to input marks

for (int j = 0; j < NUM_SUBJECTS; j++) {

System.out.print("Enter marks for " + subjects[j] + ": ");

subjectMarks[i][j] = scanner.nextFloat(); // Store subject marks

}
// Now prompt for opener, midTerm, and endTerm marks after all subjects are entered

System.out.print("Opener marks: ");

float opener = scanner.nextFloat();

System.out.print("Enter midTerm marks: ");

float midTerm = scanner.nextFloat();

System.out.print("endTerm marks: ");

float endTerm = scanner.nextFloat();

scanner.nextLine(); // Consume newline character

// Calculate average marks for all subjects

for (int j = 0; j < NUM_SUBJECTS; j++) {

studentAverages[i][j] = (subjectMarks[i][j] + opener + midTerm + endTerm) / 3; //

Average with opener, midTerm, endTerm

System.out.println("\nGenerating reports for all students...\n");

for (int i = 0; i < NUM_STUDENTS; i++) {

System.out.println("Report for " + studentNames[i]);

for (int j = 0; j < NUM_SUBJECTS; j++) {

System.out.println(subjects[j] + " Average: " + studentAverages[i][j]);

printGrade(studentAverages[i][j]);

System.out.println("---------------------------");

}
}

// Method to print and determine grades

public static void printGrade(float average) {

if (average < 40) {

System.out.println("Grade: Below Expectation");

} else if (average < 50) {

System.out.println("Grade: Approaches Expectation");

} else if (average < 70) {

System.out.println("Grade: Meets Expectation");

} else {

System.out.println("Grade: Exceeds Expectation");

You might also like