Skip to content

Commit 44cec41

Browse files
Added Grade.java with grading method
1 parent 6e4037c commit 44cec41

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/main/Grade.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
public class Grade {
2+
private String courseName;
3+
private int marks;
4+
private String grade;
5+
private double gradePoint;
6+
7+
// Constructor
8+
public Grade(String courseName, int marks) {
9+
this.courseName = courseName;
10+
this.marks = marks;
11+
setGradeAndPoint(marks); // auto-assign grade and GPA
12+
}
13+
14+
// Getters
15+
public String getCourseName() {
16+
return courseName;
17+
}
18+
19+
public int getMarks() {
20+
return marks;
21+
}
22+
23+
public String getGrade() {
24+
return grade;
25+
}
26+
27+
public double getGradePoint() {
28+
return gradePoint;
29+
}
30+
31+
// Setters
32+
public void setCourseName(String courseName) {
33+
this.courseName = courseName;
34+
}
35+
36+
public void setMarks(int marks) {
37+
this.marks = marks;
38+
setGradeAndPoint(marks); // update grade & GPA when marks change
39+
}
40+
41+
// Private helper to assign grade & GPA based on KUET rules
42+
private void setGradeAndPoint(int marks) {
43+
if (marks >= 80) { grade = "A+"; gradePoint = 4.00; }
44+
else if (marks >= 75) { grade = "A"; gradePoint = 3.75; }
45+
else if (marks >= 70) { grade = "A-"; gradePoint = 3.50; }
46+
else if (marks >= 65) { grade = "B+"; gradePoint = 3.25; }
47+
else if (marks >= 60) { grade = "B"; gradePoint = 3.00; }
48+
else if (marks >= 55) { grade = "B-"; gradePoint = 2.75; }
49+
else if (marks >= 50) { grade = "C+"; gradePoint = 2.50; }
50+
else if (marks >= 45) { grade = "C"; gradePoint = 2.25; }
51+
else if (marks >= 40) { grade = "D"; gradePoint = 2.00; }
52+
else { grade = "F"; gradePoint = 0.00; }
53+
}
54+
55+
// Print method
56+
public void printInfo() {
57+
System.out.println("Course: " + courseName +
58+
" | Marks: " + marks +
59+
" | Grade: " + grade +
60+
" | GPA: " + gradePoint);
61+
}
62+
}
63+
// End of Grade class

0 commit comments

Comments
 (0)