Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

College Grading System Code

Uploaded by

Rayhann Infante
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

College Grading System Code

Uploaded by

Rayhann Infante
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class CollegeGradeSystem {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Student> students = new ArrayList<>();

System.out.print("Enter number of students: ");


int numStudents = scanner.nextInt();

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


System.out.print("Enter student name: ");
String name = scanner.next();
System.out.print("Enter attendance score: ");
int attendance = scanner.nextInt();
System.out.print("Enter quiz score: ");
int quiz = scanner.nextInt();
System.out.print("Enter activity score: ");
int activity = scanner.nextInt();
System.out.print("Enter exam score: ");
int exam = scanner.nextInt();
students.add(new Student(name, attendance, quiz, activity, exam));
}
scanner.close();

Collections.sort(students,
Comparator.comparingDouble(Student::getFinalGrade).reversed());

int top5Count = 0;
System.out.println("\nTop 5 Students:");
for (Student student : students) {
if (top5Count < 5) {
System.out.println(student.getName() + "'s Final Grade: " + student.getFinalGrade());
printResult(student.getFinalGrade(), student.getName());
top5Count++;
} else {
break;
}
}

System.out.println("\nStudents Not in Top 5:");


for (Student student : students.subList(5, students.size())) {
System.out.println(student.getName() + "'s Final Grade: " + student.getFinalGrade());
printResult(student.getFinalGrade(), student.getName());
}
}

private static void printResult(double weightedScore, String studentName) {


if (weightedScore >= 96) {
System.out.println(studentName + " 1.00 Passed! Excellent grade");
} else if (weightedScore >= 94) {
System.out.println(studentName + " 1.25 Passed! Very good grade");
} else if (weightedScore >= 92) {
System.out.println(studentName + " 1.50 Passed! Very good grade");
} else if (weightedScore >= 89) {
System.out.println(studentName + " 1.75 Passed! Good grade");
} else if (weightedScore >= 87) {
System.out.println(studentName + " 2.00 Passed! Good grade");
} else if (weightedScore >= 84) {
System.out.println(studentName + " 2.25 Passed! Good grade");
} else if (weightedScore >= 82) {
System.out.println(studentName + " 2.50 Passed! Fair grade");
} else if (weightedScore >= 81) {
System.out.println(studentName + " 2.75 Passed! Fair grade");
} else if (weightedScore >= 79) {
System.out.println(studentName + " 2.75 Passed! Fair grade");
} else if (weightedScore >= 77) {
System.out.println(studentName + " 3.00 Passed!");
} else if (weightedScore >= 75) {
System.out.println(studentName + " 3.00 Passed!");
} else {
System.out.println(studentName + " 5.00 Failed grade");
}
}
}

class Student {
private String name;
private int attendance;
private int quiz;
private int activity;
private int exam;
private double weightedGrade;

public Student(String name, int attendance, int quiz, int activity, int exam) {
this.name = name;
this.attendance = attendance;
this.quiz = quiz;
this.activity = activity;
this.exam = exam;
this.weightedGrade = calculateWeightedGrade(attendance, quiz, activity, exam);
}

private double calculateWeightedGrade(int attendance, int quiz, int activity, int exam) {
return (attendance * 0.1) + (quiz * 0.3) + (activity * 0.3) + (exam * 0.3);
}

public String getName() {


return name;
}

public double getFinalGrade() {


return weightedGrade;
}
}

You might also like