-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchoolGradingSystem.java
More file actions
170 lines (142 loc) · 7.95 KB
/
SchoolGradingSystem.java
File metadata and controls
170 lines (142 loc) · 7.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import java.util.Scanner;
// Abstract class representing a gradeable item
abstract class GradeableItem {
private String itemName;
private int maxScore;
private int obtainedScore;
// Constructor
public GradeableItem(String itemName, int maxScore, int obtainedScore) {
this.itemName = itemName;
this.maxScore = maxScore;
this.obtainedScore = obtainedScore;
}
// Abstract method to calculate grade
public abstract String calculateGrade();
// Getters and Setters
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public int getMaxScore() {
return maxScore;
}
public void setMaxScore(int maxScore) {
this.maxScore = maxScore;
}
public int getObtainedScore() {
return obtainedScore;
}
public void setObtainedScore(int obtainedScore) {
this.obtainedScore = obtainedScore;
}
}
// Concrete subclass representing an Exam
class Exam extends GradeableItem {
// Constructor
public Exam(String itemName, int maxScore, int obtainedScore) {
super(itemName, maxScore, obtainedScore);
}
// Override calculateGrade method
public String calculateGrade() {
double percentage = (double) getObtainedScore() / getMaxScore() * 100;
// Determine grade based on percentage
if (percentage >= 90) {
return "A";
} else if (percentage >= 80) {
return "B";
} else if (percentage >= 70) {
return "C";
} else if (percentage >= 60) {
return "D";
} else {
return "F";
}
}
// Method to get percentage
public double calculatePercentage() {
return (double) getObtainedScore() / getMaxScore() * 100;
}
}
// Main class to test the School Grading System
public class SchoolGradingSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("███████╗ ██████╗██╗ ██╗ ██████╗ ██████╗ ██╗ ");
System.out.println("██╔════╝██╔════╝██║ ██║██╔═══██╗██╔═══██╗██║ ");
System.out.println("███████╗██║ ███████║██║ ██║██║ ██║██║ ");
System.out.println("╚════██║██║ ██╔══██║██║ ██║██║ ██║██║ ");
System.out.println("███████║╚██████╗██║ ██║╚██████╔╝╚██████╔╝███████╗ ");
System.out.println("╚══════╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝ ");
System.out.println();
System.out.println("\t ██████╗ ██████╗ █████╗ ██████╗ ██╗███╗ ██╗ ██████╗ ");
System.out.println("\t ██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██║████╗ ██║██╔════╝ ");
System.out.println("\t ██║ ███╗██████╔╝███████║██║ ██║██║██╔██╗ ██║██║ ███╗ ");
System.out.println("\t ██║ ██║██╔══██╗██╔══██║██║ ██║██║██║╚██╗██║██║ ██║ ");
System.out.println("\t ╚██████╔╝██║ ██║██║ ██║██████╔╝██║██║ ╚████║╚██████╔╝ ");
System.out.println("\t ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ");
System.out.println();
System.out.println("\t \t \t \t \t ███████╗██╗ ██╗███████╗████████╗███████╗███╗ ███╗");
System.out.println("\t \t \t \t \t ██╔════╝╚██╗ ██╔╝██╔════╝╚══██╔══╝██╔════╝████╗ ████║");
System.out.println("\t \t \t \t \t ███████╗ ╚████╔╝ ███████╗ ██║ █████╗ ██╔████╔██║");
System.out.println("\t \t \t \t \t ╚════██║ ╚██╔╝ ╚════██║ ██║ ██╔══╝ ██║╚██╔╝██║");
System.out.println("\t \t \t \t \t ███████║ ██║ ███████║ ██║ ███████╗██║ ╚═╝ ██║");
System.out.println("\t \t \t \t \t ╚══════╝ ╚═╝ ╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝");
System.out.println(
"________________________________________________________________________________________________");
System.out.println("\n \t Enter Student Dtails");
System.out.print("Enter student name: ");
String studentName = scanner.nextLine();
System.out.print("Enter class: ");
String studentClass = scanner.nextLine();
// Input exam details
System.out.print("Enter subject name: ");
String subjectName = scanner.nextLine();
System.out.print("Enter maximum marks: ");
int maxMarks = scanner.nextInt();
// Input obtained marks (with validation)
int obtainedMarks;
do {
System.out.print("Enter obtained marks (must be <= " + maxMarks + "): ");
obtainedMarks = scanner.nextInt();
if (obtainedMarks > maxMarks) {
System.out.println("Obtained marks cannot be greater than maximum marks.");
}
} while (obtainedMarks > maxMarks);
// Create Exam object
Exam exam = new Exam(subjectName, maxMarks, obtainedMarks);
// Calculate grade and percentage
String grade = exam.calculateGrade();
double percentage = exam.calculatePercentage();
// Output results
System.out.println("\nStudent Name: " + studentName);
System.out.println("Class: " + studentClass);
System.out.println("Subject Name: " + exam.getItemName());
System.out.println("Max Marks: " + exam.getMaxScore());
System.out.println("Obtained Marks: " + exam.getObtainedScore());
System.out.printf("Percentage: %.2f%%\n", percentage);
System.out.println("Grade: " + grade);
// Complimentary message based on grade
switch (grade) {
case "A":
System.out.println("Excellent work! Keep it up, " + studentName + "!");
break;
case "B":
System.out.println("Well done! Good job, " + studentName + "!");
break;
case "C":
System.out.println("Good effort! Keep improving, " + studentName + "!");
break;
case "D":
System.out.println("You passed! Keep studying, " + studentName + "!");
break;
case "F":
System.out.println("Sorry, you did not pass. Keep learning and try again, " + studentName + "!");
break;
default:
System.out.println("Invalid grade");
}
scanner.close();
}
}