-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGrading.java
More file actions
200 lines (160 loc) · 6.22 KB
/
Copy pathStudentGrading.java
File metadata and controls
200 lines (160 loc) · 6.22 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import java.util.Scanner;
public class StudentGrading {
static double[] mathArr = new double[100];
static double[] phyArr = new double[100];
static double[] chemArr = new double[100];
static double[] engArr = new double[100];
static double[] urduArr = new double[100];
static String[] nameArr = new String[100];
static int[] standardArr = new int[100];
static String[] gradeArr = new String[100];
static int times = 0;
// ================= CLI MAIN =================
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("\nStudent Grading System");
System.out.println("1. Add Students Marks");
System.out.println("2. View Student Marks");
System.out.println("3. View Class Average");
System.out.println("4. Exit");
String choice = sc.nextLine();
if (choice.equals("1")) {
addStudentsMarks(sc);
} else if (choice.equals("2")) {
viewStudentMarks(sc);
} else if (choice.equals("3")) {
viewClassAverage();
} else if (choice.equals("4")) {
System.out.println("Thank you for using the system!");
break;
} else {
System.out.println("Invalid input!");
}
}
}
// ================= ADD STUDENT (CLI) =================
public static void addStudentsMarks(Scanner sc) {
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Class: ");
int standard = sc.nextInt();
System.out.print("Math: ");
double math = sc.nextDouble();
System.out.print("Physics: ");
double phy = sc.nextDouble();
System.out.print("Chemistry: ");
double chem = sc.nextDouble();
System.out.print("English: ");
double eng = sc.nextDouble();
System.out.print("Urdu: ");
double urdu = sc.nextDouble();
sc.nextLine();
mathArr[times] = math;
phyArr[times] = phy;
chemArr[times] = chem;
engArr[times] = eng;
urduArr[times] = urdu;
nameArr[times] = name;
standardArr[times] = standard;
int index = times;
times++;
System.out.println(buildTranscript(index));
}
// ================= VIEW STUDENT (CLI) =================
public static void viewStudentMarks(Scanner sc) {
System.out.print("Enter student name: ");
String find = sc.nextLine();
for (int i = 0; i < times; i++) {
if (nameArr[i].equalsIgnoreCase(find)) {
System.out.println(buildTranscript(i));
return;
}
}
System.out.println("Student not found!");
}
// ================= CLASS AVERAGE =================
public static void viewClassAverage() {
if (times == 0) {
System.out.println("No data available!");
return;
}
double mathSum = 0, phySum = 0, chemSum = 0, engSum = 0, urduSum = 0;
for (int i = 0; i < times; i++) {
mathSum += mathArr[i];
phySum += phyArr[i];
chemSum += chemArr[i];
engSum += engArr[i];
urduSum += urduArr[i];
}
System.out.println("=================================");
System.out.println("Math Avg: " + (mathSum / times));
System.out.println("Physics Avg: " + (phySum / times));
System.out.println("Chemistry Avg: " + (chemSum / times));
System.out.println("English Avg: " + (engSum / times));
System.out.println("Urdu Avg: " + (urduSum / times));
System.out.println("=================================");
}
// ================= CORE TRANSCRIPT LOGIC =================
public static String buildTranscript(int i) {
double total = mathArr[i] + phyArr[i] + chemArr[i] + engArr[i] + urduArr[i];
String grade;
if (total >= 450) grade = "A*";
else if (total >= 400) grade = "A";
else if (total >= 350) grade = "B";
else if (total >= 300) grade = "C";
else if (total >= 250) grade = "D";
else grade = "Fail";
gradeArr[i] = grade;
double percent = (total / 500.0) * 100;
String transcript = "";
transcript += "=====================================\n";
transcript += "Name: " + nameArr[i] + "\n";
transcript += "Class: " + standardArr[i] + "\n";
transcript += "=====================================\n";
transcript += "Math: " + mathArr[i] + "\n";
transcript += "Physics: " + phyArr[i] + "\n";
transcript += "Chemistry: " + chemArr[i] + "\n";
transcript += "English: " + engArr[i] + "\n";
transcript += "Urdu: " + urduArr[i] + "\n";
transcript += "-------------------------------------\n";
transcript += "Total: " + total + " / 500\n";
transcript += "Grade: " + grade + "\n";
transcript += "Percentage: " + percent + "%\n";
transcript += "=====================================\n";
return transcript;
}
// ================= JAVA FX SUPPORT =================
// Add student from FX
public static String addStudentFromFX(
String name, int standard,
double math, double phy, double chem, double eng, double urdu) {
mathArr[times] = math;
phyArr[times] = phy;
chemArr[times] = chem;
engArr[times] = eng;
urduArr[times] = urdu;
nameArr[times] = name;
standardArr[times] = standard;
int index = times;
times++;
return buildTranscript(index);
}
// For ListView
public static String[] getStudentNames() {
String[] arr = new String[times];
for (int i = 0; i < times; i++) {
arr[i] = nameArr[i];
}
return arr;
}
// For FX transcript display
public static String getStudentTranscript(String name) {
for (int i = 0; i < times; i++) {
if (nameArr[i].equalsIgnoreCase(name)) {
return buildTranscript(i);
}
}
return "Student not found!";
}
}