Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Cj Castro
Added: May 15, 2021 6:18 AM
Views: 502
Tags: no tags
  1.   String inputCourseName = courseTF.getText();
  2.         String inputName = studentTF.getText();
  3.         boolean validCourse = false;
  4.         boolean validStudent = false;
  5.         Teacher teacher;
  6.         try {
  7.             Double inputGrade = Double.parseDouble(String.format("%s",scoreTF.getText()));   // possibility of crashing
  8.             // If the course does not exist or is not taught by that teacher,
  9.             // show the error message: You do not teach this course
  10.             if (user instanceof Teacher) {
  11.                 teacher = (Teacher) user;
  12.                
  13.                 // Step 1: Take out each course by the teacher
  14.                 for (Course existCourse : teacher.getTeachingCourses()) {
  15.                     for (Course schoolCourse : VanierSchoolSystem.courses)
  16.                         if (existCourse.getCourseName().equalsIgnoreCase(inputCourseName) &&
  17.                                 existCourse.equals(schoolCourse))
  18.  
  19.                         // Step 2 : if course exist, go check if that student exist in that course
  20.                         for (Student courseStudent : schoolCourse.getRegsStudents()) {
  21.                             if (courseStudent.fname.equalsIgnoreCase(inputName)) {
  22.                                 addStatusMsgL.setForeground(Color.GREEN);
  23.                                 addStatusMsgL.setText("The score is added successfully");
  24.                             }    
  25.                     }
  26.                        
  27.                 if (!validStudent) {
  28.                     addStatusMsgL.setForeground(Color.RED);
  29.                     addStatusMsgL.setText("The student has not registered this course");
  30.                 }
  31.                    
  32.                 }  
  33.                 if (!validCourse) {
  34.                     addStatusMsgL.setForeground(Color.RED);
  35.                     addStatusMsgL.setText("You do not teach this course");
  36.                 }
  37.             }
  38.         }
  39.         catch (NumberFormatException e) {
  40.             System.out.println(e);
  41.             System.out.println(e.getMessage());
  42.         }
  43.     }