diff --git a/JavaFinalProject.iml b/JavaFinalProject.iml index c90834f..86d3dd7 100644 --- a/JavaFinalProject.iml +++ b/JavaFinalProject.iml @@ -4,8 +4,25 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/generation/model/Student.java b/src/com/generation/model/Student.java index 0897ebe..f1805c2 100644 --- a/src/com/generation/model/Student.java +++ b/src/com/generation/model/Student.java @@ -22,8 +22,9 @@ public Student( String id, String name, String email, Date birthDate ) } public void enrollToCourse( Course course ) - { - //TODO implement this method + {//TODO implement this method + + courses.add(course); } public void registerApprovedCourse( Course course ) @@ -32,13 +33,17 @@ public void registerApprovedCourse( Course course ) } - public boolean isAttendingCourse( String courseCode ) - { + public boolean isAttendingCourse( String courseCode ) { //TODO implement this method + for (Course course : courses) { + if (course.getCode().equals(courseCode)) { + return true; + } + } return false; } - @Override +@Override public double getAverage() { return average; diff --git a/src/com/generation/service/StudentService.java b/src/com/generation/service/StudentService.java index f980e40..fc22471 100644 --- a/src/com/generation/service/StudentService.java +++ b/src/com/generation/service/StudentService.java @@ -27,8 +27,18 @@ public Student findStudent( String studentId ) public void showSummary() { //TODO implement + + System.out.println( "Registered Students:" ); + for ( String key : students.keySet() ) + { + Student student = students.get( key ); + System.out.println( student.toString() ); + } + } + + public void enrollToCourse( String studentId, Course course ) { if ( students.containsKey( studentId ) ) diff --git a/src/com/generation/utils/PrinterHelper.java b/src/com/generation/utils/PrinterHelper.java index 6f1ca9b..1f53c3c 100644 --- a/src/com/generation/utils/PrinterHelper.java +++ b/src/com/generation/utils/PrinterHelper.java @@ -8,44 +8,60 @@ import java.util.Date; import java.util.Scanner; -public class PrinterHelper -{ - - public static void showMainMenu(){ - System.out.println( "|-------------------------------|" ); - System.out.println( "| Welcome to StudentGen |" ); - System.out.println( "|-------------------------------|" ); - System.out.println( "| Select 1 option: |" ); - System.out.println( "| . 1 Register Student |" ); - System.out.println( "| . 2 Find Student |" ); - System.out.println( "| . 3 Enroll Student to Course |" ); - System.out.println( "| . 4 Show Students Summary |" ); - System.out.println( "| . 5 Show Courses Summary |" ); - System.out.println( "| . 6 Exit |" ); - System.out.println( "|-------------------------------|" ); +public class PrinterHelper { + + public static void showMainMenu() { + System.out.println("|-------------------------------|"); + System.out.println("| Welcome to StudentGen |"); + System.out.println("|-------------------------------|"); + System.out.println("| Select 1 option: |"); + System.out.println("| . 1 Register Student |"); + System.out.println("| . 2 Find Student |"); + System.out.println("| . 3 Enroll Student to Course |"); + System.out.println("| . 4 Show Students Summary |"); + System.out.println("| . 5 Show Courses Summary |"); + System.out.println("| . 6 Exit |"); + System.out.println("|-------------------------------|"); } - public static Student createStudentMenu( Scanner scanner ) - throws ParseException - { - System.out.println( "|-------------------------------------|" ); - System.out.println( "| . 1 Register Student |" ); - System.out.println( "|-------------------------------------|" ); - System.out.println( "| Enter student name: |" ); + public static Student createStudentMenu(Scanner scanner) + throws ParseException { + System.out.println("|-------------------------------------|"); + System.out.println("| . 1 Register Student |"); + System.out.println("|-------------------------------------|"); + System.out.println("| Enter student name: |"); String name = scanner.next(); - System.out.println( "| Enter student ID: |" ); + System.out.println("| Enter student ID: |"); String id = scanner.next(); - System.out.println( "| Enter student email: |" ); + 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"); + System.out.println("| Enter student birth date(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()); - System.out.println( "|-------------------------------------|" ); - Student student = new Student( id, name, email, birthDate ); - System.out.println( "Student Successfully Registered! " ); + + boolean aDate = true; + Date birthday = null; + while(aDate) { + try { + birthday = formatter.parse(scanner.next()); + aDate = false; + } catch (ParseException d) { + + System.out.println("Invalid Date"); + System.out.println("| Enter student birth date(mm/dd/yyyy)|"); + } + } + + + System.out.println("|-------------------------------------|"); + Student student = new Student(id, name, email, birthday); + System.out.println("Student Successfully Registered! "); System.out.println(student); return student; } } + + + diff --git a/test/com/generation/service/CourseServiceTest.java b/test/com/generation/service/CourseServiceTest.java new file mode 100644 index 0000000..6d3a06c --- /dev/null +++ b/test/com/generation/service/CourseServiceTest.java @@ -0,0 +1,28 @@ +package com.generation.service; +import com.generation.model.Course; +import com.generation.model.Student; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class CourseServiceTest { +CourseService courseService = new CourseService(); + + @Test + void registerCourse() { + Course course1= new Course ("INTRO-WEB-4", "Advanced HTML", 9, null); + courseService.registerCourse(course1); + Course course2 = courseService.getCourse("INTRO-WEB-4"); + assertEquals(course1, course2); + } + + @Test + void enrollStudent() { + Student nicole = new Student("1", "Nicole", "emaile@email.com", null); + courseService.enrollStudent("INTRO-WEB-4", nicole); + assertTrue(true); + + } + +} \ No newline at end of file diff --git a/test/com/generation/service/StudentServiceTest.java b/test/com/generation/service/StudentServiceTest.java new file mode 100644 index 0000000..c7f144b --- /dev/null +++ b/test/com/generation/service/StudentServiceTest.java @@ -0,0 +1,26 @@ +package com.generation.service; + +import org.junit.jupiter.api.Test; +import com.generation.model.Student; +import static org.junit.jupiter.api.Assertions.*; + +class StudentServiceTest { + + public StudentService studentService = new StudentService(); + + @Test + public void subscribeStudent() { + Student nicole = new Student("1", "Nicole", "emaile@email.com", null); + studentService.subscribeStudent(nicole); +// assertEquals(nicole, nicole); + assertTrue(true); + } + + @Test + public void findStudent() { + Student nicole = studentService.findStudent(""); + assertNull(nicole); + + } +} +