-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentInfoSys.java
453 lines (387 loc) · 21.2 KB
/
StudentInfoSys.java
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
package project;
import javax.swing.JOptionPane;
public class StudentInfoSys extends javax.swing.JFrame {
private Student [] studentArray = new Student [1000];
private int studentIndex = 0;
public StudentInfoSys() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jOptionPane1 = new javax.swing.JOptionPane();
jScrollPane2 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jOptionPane2 = new javax.swing.JOptionPane();
jOptionPane3 = new javax.swing.JOptionPane();
jOptionPane4 = new javax.swing.JOptionPane();
jOptionPane5 = new javax.swing.JOptionPane();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
mathRB = new javax.swing.JRadioButton();
multiRB = new javax.swing.JRadioButton();
indRB = new javax.swing.JRadioButton();
nameTF = new javax.swing.JTextField();
matricTF = new javax.swing.JTextField();
courseworkTF = new javax.swing.JTextField();
examTF = new javax.swing.JTextField();
displayBTN = new javax.swing.JButton();
resetBTN = new javax.swing.JButton();
addBTN = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
outputTA = new javax.swing.JTextArea();
searchBTN = new javax.swing.JButton();
showBTN = new javax.swing.JButton();
exitBTN = new javax.swing.JButton();
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane2.setViewportView(jTable1);
jOptionPane2.setName(""); // NOI18N
jOptionPane2.getAccessibleContext().setAccessibleName("");
jOptionPane2.getAccessibleContext().setAccessibleDescription("");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Student Infomation System");
jLabel1.setText("Name :");
jLabel2.setText("Matric. No :");
jLabel3.setText("Program :");
jLabel4.setText("Total Course Work Mark : ");
jLabel5.setText("Final Exam Mark : ");
buttonGroup1.add(mathRB);
mathRB.setText("B.Sc.Math");
mathRB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mathRBActionPerformed(evt);
}
});
buttonGroup1.add(multiRB);
multiRB.setText("B.Sc.Multimedia");
buttonGroup1.add(indRB);
indRB.setText("B.Sc.Ind");
nameTF.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nameTFActionPerformed(evt);
}
});
displayBTN.setText("Display");
displayBTN.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
displayBTNActionPerformed(evt);
}
});
resetBTN.setText("Reset");
resetBTN.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resetBTNActionPerformed(evt);
}
});
addBTN.setText("Add");
addBTN.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addBTNActionPerformed(evt);
}
});
outputTA.setColumns(20);
outputTA.setRows(5);
jScrollPane1.setViewportView(outputTA);
searchBTN.setText("Search");
searchBTN.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
searchBTNActionPerformed(evt);
}
});
showBTN.setText("Show");
showBTN.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
showBTNActionPerformed(evt);
}
});
exitBTN.setText("Exit");
exitBTN.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitBTNActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(nameTF)
.addComponent(matricTF)
.addComponent(courseworkTF)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(indRB)
.addComponent(multiRB)
.addComponent(mathRB))
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(examTF))
.addGap(76, 76, 76))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 402, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(addBTN, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(displayBTN, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(resetBTN, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(searchBTN, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(showBTN, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(exitBTN, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(42, 42, 42))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(34, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(nameTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(matricTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(mathRB))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(multiRB)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(indRB)
.addGap(14, 14, 14)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(courseworkTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(examTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(displayBTN)
.addComponent(resetBTN)
.addComponent(addBTN)
.addComponent(searchBTN)
.addComponent(showBTN))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(exitBTN)
.addGap(18, 18, 18))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void mathRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mathRBActionPerformed
}//GEN-LAST:event_mathRBActionPerformed
private void nameTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameTFActionPerformed
}//GEN-LAST:event_nameTFActionPerformed
private void resetBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetBTNActionPerformed
studentIndex = 0;
JOptionPane.showMessageDialog(null, "The data is reset.");
outputTA.setText("");
}//GEN-LAST:event_resetBTNActionPerformed
private void addBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBTNActionPerformed
String name = nameTF.getText();
int matric = Integer.parseInt(matricTF.getText());
double coursework = Double.parseDouble(courseworkTF.getText());
double exam = Double.parseDouble(examTF.getText());
boolean result = true;
String program = "";
if((coursework < 0) || (coursework > 100)){
JOptionPane.showMessageDialog(null,"Please enter a valid coursework marks. ");
result = false;
}
if((exam < 0) || (exam > 100)){
JOptionPane.showMessageDialog(null,"Please enter a valid exam marks. ");
result = false;
}
if(mathRB.isSelected() == true){
program = "B.Sc.Math";
}
else if(multiRB.isSelected() == true){
program = "B.Sc.Multimedia";
}
else if(indRB.isSelected() == true){
program = "B.Sc. Ind";
}
else {
JOptionPane.showMessageDialog(null, "Please select the course");
result = false;
}
if(result == true){
outputTA.setText("One student infomation is successfully added.\n");
studentArray[studentIndex] = new Student(name, matric, program, coursework, exam);
studentIndex++;
}else{
outputTA.setText("The student data is not created. \n");
}
nameTF.setText("");
matricTF.setText("");
courseworkTF.setText("");
examTF.setText("");
buttonGroup1.clearSelection();
outputTA.append("Number of student data added = " + studentIndex );
}//GEN-LAST:event_addBTNActionPerformed
private void displayBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayBTNActionPerformed
outputTA.setText("Displaying student data: \n \n");
for (int i = 0; i< studentIndex; i++ ){
outputTA.append("Name : " + studentArray[i].getStudent() + "\n");
outputTA.append("Matric No. : " + studentArray[i].getMatric() + "\n");
outputTA.append("Program : " + studentArray[i].getProgram() + "\n");
outputTA.append("Total Course work mark : " + studentArray[i].getCoursework() + "\n");
outputTA.append("Final exam mark : " + studentArray[i].getExam() + "\n");
outputTA.append("Grade : " + studentArray[i].computeGrade() + "\n");
outputTA.append("================================================= \n");
}
}//GEN-LAST:event_displayBTNActionPerformed
private void searchBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchBTNActionPerformed
int matric = Integer.parseInt(JOptionPane.showInputDialog("Please enter the Matric No."));
int i;
for ( i = 0; i < studentIndex; i++) {
if (matric == studentArray[i].getMatric()) {
outputTA.setText("Name : " + studentArray[i].getStudent() + "\n");
outputTA.append("Matric No. : " + studentArray[i].getMatric() + "\n");
outputTA.append("Program : " + studentArray[i].getProgram() + "\n");
outputTA.append("Total Course work mark : " + studentArray[i].getCoursework() + "\n");
outputTA.append("Final exam mark : " + studentArray[i].getExam() + "\n");
outputTA.append("Grade : " + studentArray[i].computeGrade() + "\n");
break;
}
}
if(i==studentIndex){
JOptionPane.showMessageDialog(null,"The matric number cannot search");
}
}//GEN-LAST:event_searchBTNActionPerformed
private void showBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showBTNActionPerformed
outputTA.setText("The distribution is as follow: \n \n");
int aPlus = 0;
int a = 0;
int aMinus = 0;
int bPlus = 0;
int b = 0;
int bMinus = 0;
int cPlus = 0;
int c = 0;
int cMinus = 0;
int dPlus = 0;
int d = 0;
int f = 0;
for (int i = 0; i< studentIndex; i++ ){
switch(studentArray[i].computeGrade()){
case "A+" : aPlus++; break;
case "A" : a++; break;
case "A-" : aMinus++; break;
case "B+" : bPlus++; break;
case "B" : b++; break;
case "B-" : bMinus++; break;
case "C+" : cPlus++; break;
case "C" : c++; break;
case "C-" : cMinus++; break;
case "D+" : dPlus++; break;
case "D" : d++; break;
default : f++; break;
}
}
outputTA.append("The total number of Grade A+ is " + aPlus + "\n");
outputTA.append("The total number of Grade A is " + a + "\n");
outputTA.append("The total number of Grade A- is " + aMinus + "\n");
outputTA.append("The total number of Grade B+ is " + bPlus + "\n");
outputTA.append("The total number of Grade B is " + b + "\n");
outputTA.append("The total number of Grade B- is " + bMinus + "\n");
outputTA.append("The total number of Grade C+ is " + cPlus + "\n");
outputTA.append("The total number of Grade C is " + c + "\n");
outputTA.append("The total number of Grade C- is " + cMinus + "\n");
outputTA.append("The total number of Grade D+ is " + dPlus + "\n");
outputTA.append("The total number of Grade D is " + d + "\n");
outputTA.append("The total number of Grade F is " + f + "\n");
}//GEN-LAST:event_showBTNActionPerformed
private void exitBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitBTNActionPerformed
System.exit(1);
}//GEN-LAST:event_exitBTNActionPerformed
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(StudentInfoSys.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(StudentInfoSys.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(StudentInfoSys.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(StudentInfoSys.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> {
new StudentInfoSys().setVisible(true);
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addBTN;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JTextField courseworkTF;
private javax.swing.JButton displayBTN;
private javax.swing.JTextField examTF;
private javax.swing.JButton exitBTN;
private javax.swing.JRadioButton indRB;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JOptionPane jOptionPane1;
private javax.swing.JOptionPane jOptionPane2;
private javax.swing.JOptionPane jOptionPane3;
private javax.swing.JOptionPane jOptionPane4;
private javax.swing.JOptionPane jOptionPane5;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
private javax.swing.JRadioButton mathRB;
private javax.swing.JTextField matricTF;
private javax.swing.JRadioButton multiRB;
private javax.swing.JTextField nameTF;
private javax.swing.JTextArea outputTA;
private javax.swing.JButton resetBTN;
private javax.swing.JButton searchBTN;
private javax.swing.JButton showBTN;
// End of variables declaration//GEN-END:variables
}