0% found this document useful (0 votes)
20 views7 pages

Grade Predction Calculator

Uploaded by

pavanka22072004
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)
20 views7 pages

Grade Predction Calculator

Uploaded by

pavanka22072004
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/ 7

EX.

NO: MINI PROJECT - GRADE PREDICTION CALCULATOR


DATE:

AIM:

To develop a Grade Prediction System using Java that can manage student data, calculate
grades based on weightages, predict grades, and save or load data for reuse.

ALGORITHM:
1. Initialization:
o Create a student class to store student details, grades, and weightages.
o Create a GradeCalculator class to determine letter grades from numeric
grades.
o Create a FileHandler class to handle saving and loading data from files.
2. Main Program Flow:
o Load existing student data (if available) from a file using the FileHandler class.
o Display a menu with options:
1. Add a new student.
2. View student grades.
3. Calculate predicted grades.
4. Save data to a file.
5. Exit the program.
3. Adding a Student:
o Prompt the user to enter the student's name and ID.
o Allow the user to input grade components, their scores, and respective
weightages.
o Validate that the total weightage sums to 100%.
4. Viewing Grades:
o Prompt the user for a student ID.
o Locate the student using the ID and display their grade breakdown.
5. Calculating Predicted Grades:
o Prompt the user for a student ID.
o Locate the student using the ID.
o Calculate the predicted grade by multiplying each grade with its weightage
and summing up the weighted values.
o Convert the numeric grade to a letter grade using the GradeCalculator class.
6. Saving Data:
o Write student data to a file in a structured format using the FileHandler class.
7. Exiting:
o End the program.
8. Error Handling:
o Handle invalid inputs and exceptions (e.g., file read/write errors, invalid
weightages).
PROGRAM:
package GradePredction;
import java.io.*;
import java.util.*;
public class GradePredictionApp {
static class Student {
private String studentName;
private String studentID;
private Map<String, Double> grades = new HashMap<>();
private Map<String, Double> weightages = new HashMap<>();
private double predictedGrade;
public Student(String studentName, String studentID) {
this.studentName = studentName;
this.studentID = studentID;
}
public void addGrade(String component, double grade, double weight) {
grades.put(component, grade);
weightages.put(component, weight);
}
public void calculatePredictedGrade() {
double totalWeight = 0.0;
double weightedGradeSum = 0.0;
for (String component : grades.keySet()) {
double grade = grades.get(component);
double weight = weightages.get(component);
weightedGradeSum += grade * (weight / 100);
totalWeight += weight;
}
if (totalWeight == 100) {
this.predictedGrade = weightedGradeSum;
} else {
throw new IllegalArgumentException("Total weightage must be 100.");
}
}
public String getStudentName() {
return studentName;
}
public String getStudentID() {
return studentID;
}
public double getPredictedGrade() {
return predictedGrade;
}
public Map<String, Double> getGrades() {
return grades;
}
public Map<String, Double> getWeightages() {
return weightages; }
public void printGradeBreakdown() {
System.out.println("Grade Breakdown for " + studentName + ":");
for (String component : grades.keySet()) {
System.out.println(component + ": " + grades.get(component) + " (" +
weightages.get(component) + "%)");
}
}
}
static class GradeCalculator {
public static String calculateLetterGrade(double grade) {
if (grade >= 90) {
return "A";
} else if (grade >= 80) {
return "B";
} else if (grade >= 70) {
return "C";
} else if (grade >= 60) {
return "D";
} else {
return "F";
}
}
}
static class FileHandler {
public static void saveStudentData(List<Student> students, String filename) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
for (Student student : students) {
writer.write(student.getStudentID() + "," + student.getStudentName() + "\n");
for (String component : student.getGrades().keySet()) {
double grade = student.getGrades().get(component);
double weight = student.getWeightages().get(component);
writer.write(component + "," + grade + "," + weight + "\n");
} }
} catch (IOException e) {
System.out.println("Error saving data: " + e.getMessage());
} }
public static List<Student> loadStudentData(String filename) {
List<Student> students = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
String line;
Student currentStudent = null;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(",");
if (parts.length == 2) { // It's a student record
currentStudent = new Student(parts[1], parts[0]);
students.add(currentStudent);
}
else if (parts.length == 3 && currentStudent != null) {
String component = parts[0];
double grade = Double.parseDouble(parts[1]);
double weight = Double.parseDouble(parts[2]);
currentStudent.addGrade(component, grade, weight);
}
}
} catch (IOException e) {
System.out.println("Error loading data: " + e.getMessage());
}
return students;
} }
private static Scanner scanner = new Scanner(System.in);
private static List<Student> students = new ArrayList<>();
public static void main(String[] args) {
students = FileHandler.loadStudentData("students.csv");
while (true) {
System.out.println("\nGrade Prediction System");
System.out.println("1. Add a new student");
System.out.println("2. View student grades");
System.out.println("3. Calculate grade for a student");
System.out.println("4. Save data");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
addStudent();
break;
case 2:
viewStudentGrades();
break;
case 3:
calculateGrade();
break;
case 4:
saveData();
break;
case 5:
System.out.println("Goodbye!");
return;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
private static void addStudent() {
System.out.print("Enter Student Name: ");
String name = scanner.nextLine();
System.out.print("Enter Student ID: ");
String id = scanner.nextLine();
Student student = new Student(name, id);
System.out.print("How many grade components do you want to add? ");
int numComponents = scanner.nextInt();
scanner.nextLine();
for (int i = 0; i < numComponents; i++) {
System.out.print("Enter component name (e.g., Exam, Assignment): ");
String component = scanner.nextLine();
System.out.print("Enter grade for " + component + ": ");
double grade = scanner.nextDouble();
System.out.print("Enter weightage for " + component + ": ");
double weight = scanner.nextDouble();
scanner.nextLine();
student.addGrade(component, grade, weight);
}
students.add(student);
System.out.println("Student added successfully.");
}
private static void viewStudentGrades() {
System.out.print("Enter student ID to view: ");
String id = scanner.nextLine();
Student student = findStudentByID(id);
if (student != null) {
student.printGradeBreakdown();
} else {
System.out.println("Student not found.");
}
}
private static void calculateGrade() {
System.out.print("Enter student ID to calculate grade: ");
String id = scanner.nextLine();
Student student = findStudentByID(id);
if (student != null) {
student.calculatePredictedGrade();
double predictedGrade = student.getPredictedGrade();
String letterGrade = GradeCalculator.calculateLetterGrade(predictedGrade);
System.out.println("Predicted Grade for " + student.getStudentName() + ": " +
predictedGrade + "% (" + letterGrade + ")");
} else { System.out.println("Student not found.");
} }
private static void saveData() {
FileHandler.saveStudentData(students, "students.csv");
System.out.println("Data saved successfully.");
}
private static Student findStudentByID(String id) {
for (Student student : students) {
if (student.getStudentID().equals(id)) {
return student;
}
}
return null;
}
}

OUTPUT:
Grade Prediction System
1. Add a new student
2. View student grades
3. Calculate grade for a student
4. Save data
5. Exit
Enter your choice:1
Enter Student Name: John Doe
Enter Student ID: S123
How many grade components do you want to add?
2 Enter component name
Exam Enter grade for Exam: 85
Enter weightage for Exam: 50
Enter component name: Assignment
Enter grade for Assignment: 90
Enter weightage for Assignment: 50
Student added successfully.
Enter your choice: 2
Enter student ID to view: S123
Grade Breakdown for John Doe:
Exam: 85.0 (50.0%)
Assignment: 90.0 (50.0%)
Enter your choice: 3
Enter student ID to calculate grade: S123
Predicted Grade for John Doe: 87.5% (B)
Enter your choice: 4
Data saved successfully.
Enter your choice: 5
Goodbye!

APPLICATIONS:

1. Track Student Progress:


o Teachers can record and monitor student grades and predict final grades
based on weightages.
2. Grade Forecasting:
o Useful for determining potential final grades based on current performance.
3. Data Storage:
o Allows saving and loading student data for future use, reducing repetitive
manual entry.
4. Customization:
o Supports flexible grading components (e.g., quizzes, assignments, exams) and
varying weightages.

RESULT:
Thus, the java program for grade prediction calculator was successfully developed
and executed successfully.

You might also like