diff --git a/JavaFinalProject.iml b/JavaFinalProject.iml index c90834f..0910ac0 100644 --- a/JavaFinalProject.iml +++ b/JavaFinalProject.iml @@ -3,9 +3,27 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/generation/model/Student.java b/src/com/generation/model/Student.java index 0897ebe..0926470 100644 --- a/src/com/generation/model/Student.java +++ b/src/com/generation/model/Student.java @@ -23,7 +23,13 @@ public Student( String id, String name, String email, Date birthDate ) public void enrollToCourse( Course course ) { - //TODO implement this method + if(!isAttendingCourse(course.getCode())){ + //TODO implement this method + courses.add(course); + } else { + System.out.println("Student has already been enrolled in this course"); + } + } public void registerApprovedCourse( Course course ) @@ -35,6 +41,11 @@ public void registerApprovedCourse( Course course ) public boolean isAttendingCourse( String courseCode ) { //TODO implement this method + for(Course c : courses){ + if(c.getCode().equalsIgnoreCase(courseCode)){ + return true; + } + } return false; } diff --git a/src/com/generation/service/StudentService.java b/src/com/generation/service/StudentService.java index f980e40..9cbebad 100644 --- a/src/com/generation/service/StudentService.java +++ b/src/com/generation/service/StudentService.java @@ -27,6 +27,11 @@ public Student findStudent( String studentId ) public void showSummary() { //TODO implement + System.out.println("Student Summary"); + for (Student s : students.values()){ + System.out.println(s.toString()); + } + } public void enrollToCourse( String studentId, Course course ) diff --git a/src/com/generation/utils/PrinterHelper.java b/src/com/generation/utils/PrinterHelper.java index 6f1ca9b..cbf86c8 100644 --- a/src/com/generation/utils/PrinterHelper.java +++ b/src/com/generation/utils/PrinterHelper.java @@ -37,10 +37,23 @@ public static Student createStudentMenu( Scanner scanner ) String id = scanner.next(); System.out.println( "| Enter student email: |" ); String email = scanner.next(); - System.out.println( "| Enter student birth date(mm/dd/yyyy)|" ); - DateFormat formatter = new SimpleDateFormat( "mm/dd/yyyy"); + DateFormat formatter = new SimpleDateFormat( "MM/dd/yyyy"); //TODO validate date format and catch exception to avoid crash - Date birthDate = formatter.parse( scanner.next()); + boolean isValid = false; + Date birthDate = null; + do{ + + System.out.println( "| Enter student birth date(mm/dd/yyyy)|" ); + try{ + birthDate = formatter.parse( scanner.next()); + isValid = true; + } catch (ParseException ex){ + System.out.println("The date must be in mm/dd/yyyy format."); + } + }while(!isValid); + + +// Date birthDate = (Date) formatter.parse( scanner.next()); System.out.println( "|-------------------------------------|" ); Student student = new Student( id, name, email, birthDate ); System.out.println( "Student Successfully Registered! " );