diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml deleted file mode 100644 index 6e5a132..0000000 --- a/.idea/dbnavigator.xml +++ /dev/null @@ -1,462 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/jpa-buddy.xml b/.idea/jpa-buddy.xml deleted file mode 100644 index 966d5f5..0000000 --- a/.idea/jpa-buddy.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 4e2f650..03f397c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,6 @@ - + - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index b84ce3f..80b79f2 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,6 +3,7 @@ + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/JavaFinalProject.iml b/JavaFinalProject.iml index c90834f..aa67d5f 100644 --- a/JavaFinalProject.iml +++ b/JavaFinalProject.iml @@ -3,9 +3,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/generation/model/Student.java b/src/com/generation/model/Student.java index 0897ebe..9d4cda1 100644 --- a/src/com/generation/model/Student.java +++ b/src/com/generation/model/Student.java @@ -23,6 +23,12 @@ public Student( String id, String name, String email, Date birthDate ) public void enrollToCourse( Course course ) { + if(!isAttendingCourse(course.getCode())) { + courses.add(course); + } + else{ + System.out.println("You are already enrolled in this course."); + } //TODO implement this method } @@ -31,9 +37,14 @@ public void registerApprovedCourse( Course course ) approvedCourses.put( course.getCode(), course ); } - +// Will return true is the student is attending the course that correlates with the courseCode argument public boolean isAttendingCourse( String courseCode ) { + for(Course course: courses){ + if(course.getCode().equals(courseCode)) { + return true; + } + } //TODO implement this method return false; } diff --git a/src/com/generation/service/CourseServiceTest.java b/src/com/generation/service/CourseServiceTest.java new file mode 100644 index 0000000..e17bdf8 --- /dev/null +++ b/src/com/generation/service/CourseServiceTest.java @@ -0,0 +1,26 @@ +package com.generation.service; + +import static org.junit.jupiter.api.Assertions.*; + +class CourseServiceTest { + + @org.junit.jupiter.api.Test + void registerCourse() { + } + + @org.junit.jupiter.api.Test + void getCourse() { + } + + @org.junit.jupiter.api.Test + void enrollStudent() { + } + + @org.junit.jupiter.api.Test + void showEnrolledStudents() { + } + + @org.junit.jupiter.api.Test + void showSummary() { + } +} \ No newline at end of file diff --git a/src/com/generation/service/StudentService.java b/src/com/generation/service/StudentService.java index f980e40..8809c92 100644 --- a/src/com/generation/service/StudentService.java +++ b/src/com/generation/service/StudentService.java @@ -6,29 +6,35 @@ import java.util.HashMap; import java.util.Map; -public class StudentService -{ +public class StudentService { private final Map students = new HashMap<>(); - public void subscribeStudent( Student student ) - { - students.put( student.getId(), student ); + + public void subscribeStudent(Student student) { + students.put(student.getId(), student); } - public Student findStudent( String studentId ) - { - if ( students.containsKey( studentId ) ) - { - return students.get( studentId ); + public Student findStudent(String studentId) { + if (students.containsKey(studentId)) { + return students.get(studentId); } return null; } - public void showSummary() { - //TODO implement + // implement students values to showSummary + System.out.println("Registered Student: "); + for(String key: students.keySet()) + { + Student student = students.get( key ); + System.out.println(student.toString()); + //TODO implement + } } + + + public void enrollToCourse( String studentId, Course course ) { if ( students.containsKey( studentId ) ) diff --git a/src/com/generation/service/StudentServiceTest.java b/src/com/generation/service/StudentServiceTest.java new file mode 100644 index 0000000..761f15d --- /dev/null +++ b/src/com/generation/service/StudentServiceTest.java @@ -0,0 +1,24 @@ +package com.generation.service; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class StudentServiceTest { + + @Test + void subscribeStudent() { + } + + @Test + void findStudent() { + } + + @Test + void showSummary() { + } + + @Test + void enrollToCourse() { + } +} \ No newline at end of file diff --git a/src/com/generation/utils/PrinterHelper.java b/src/com/generation/utils/PrinterHelper.java index 6f1ca9b..b7f6b46 100644 --- a/src/com/generation/utils/PrinterHelper.java +++ b/src/com/generation/utils/PrinterHelper.java @@ -37,10 +37,22 @@ 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"); + boolean validDate = false; + Date birthDate = null; //TODO validate date format and catch exception to avoid crash - Date birthDate = formatter.parse( scanner.next()); + while(!validDate){ + System.out.println( "| Enter student birth date(mm/dd/yyyy)|" ); + try{ + birthDate = formatter.parse( scanner.next()); + validDate = true; + } + catch(ParseException e) { + System.out.println("Date is invalid!"); + } + } + System.out.println( "|-------------------------------------|" ); Student student = new Student( id, name, email, birthDate ); System.out.println( "Student Successfully Registered! " );