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/Main.java b/src/com/generation/Main.java index 9e24556..1349a7e 100644 --- a/src/com/generation/Main.java +++ b/src/com/generation/Main.java @@ -43,6 +43,7 @@ public static void main( String[] args ) } } while ( option != 6 ); + } private static void enrollStudentToCourse( StudentService studentService, CourseService courseService, @@ -104,4 +105,8 @@ private static void registerStudent( StudentService studentService, Scanner scan Student student = PrinterHelper.createStudentMenu( scanner ); studentService.subscribeStudent( student ); } + + + + } diff --git a/src/com/generation/model/Student.java b/src/com/generation/model/Student.java index 0897ebe..625b4cf 100644 --- a/src/com/generation/model/Student.java +++ b/src/com/generation/model/Student.java @@ -24,6 +24,7 @@ public Student( String id, String name, String email, Date birthDate ) public void enrollToCourse( Course course ) { //TODO implement this method + courses.add(course); //adds a new course to end of course arraylist } public void registerApprovedCourse( Course course ) @@ -35,6 +36,13 @@ public void registerApprovedCourse( Course course ) public boolean isAttendingCourse( String courseCode ) { //TODO implement this method + + for (Course course : courses) { + if (courseCode.equalsIgnoreCase(course.getCode())) { + return true; + } + } + return false; } diff --git a/src/com/generation/service/StudentService.java b/src/com/generation/service/StudentService.java index f980e40..d8e3640 100644 --- a/src/com/generation/service/StudentService.java +++ b/src/com/generation/service/StudentService.java @@ -4,6 +4,7 @@ import com.generation.model.Student; import java.util.HashMap; +import java.util.List; import java.util.Map; public class StudentService @@ -27,6 +28,15 @@ public Student findStudent( String studentId ) public void showSummary() { //TODO implement + + System.out.println( "Students:" ); + for ( String key : students.keySet() ) //key is student id number value is object 5 + { + Student student = students.get( key );//returns object and places it in student + System.out.println( student); //prints student +// System.out.println(student.isAttendingCourse("INTRO-WEB-1")); //tests if student is enrolled to this course + } + } 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..dce67c5 100644 --- a/src/com/generation/utils/PrinterHelper.java +++ b/src/com/generation/utils/PrinterHelper.java @@ -5,6 +5,7 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; + import java.util.Date; import java.util.Scanner; @@ -38,9 +39,22 @@ public static Student createStudentMenu( Scanner scanner ) 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()); + Date birthDate=null; + boolean validDate=false; + + while(!validDate){ + try{ + birthDate = formatter.parse( scanner.next()); + validDate=true; + } catch(ParseException error){ + System.out.println("invalid date. Please enter a valid date"); + } + } + + + System.out.println( "|-------------------------------------|" ); Student student = new Student( id, name, email, birthDate ); System.out.println( "Student Successfully Registered! " ); diff --git a/test/com/generation/service/CourseServiceTest.java b/test/com/generation/service/CourseServiceTest.java new file mode 100644 index 0000000..78c23c0 --- /dev/null +++ b/test/com/generation/service/CourseServiceTest.java @@ -0,0 +1,40 @@ +package com.generation.service; + +import com.generation.model.Course; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + + + +class CourseServiceTest { + + CourseService courseService = new CourseService();//create an object + Course course=new Course("1234","computer",4,null); + + @Test + void registerCourse() { + courseService.registerCourse(course); + assertNotNull(courseService); + } + + @Test + void getCourse() { + assertNull(courseService.getCourse("1234")); + } + + @Test + void enrollStudent() { + } + + @Test + void showEnrolledStudents() { + } + + @Test + void showSummary() { + + } + + +} \ 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..1ed5f25 --- /dev/null +++ b/test/com/generation/service/StudentServiceTest.java @@ -0,0 +1,36 @@ +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 StudentServiceTest { + + public StudentService studentService=new StudentService(); + public Student student=new Student("1234","yvette","yvette@email.com",null); + + + @Test + void subscribeStudent() { + studentService.subscribeStudent(student); //adds student object + assertTrue(studentService!=null); //checkks that student service is not null + } + + @Test + void findStudent() { + assertNull(studentService.findStudent("1234")); + + } + + @Test + void showSummary() { + + } + + @Test + void enrollToCourse() { + + } +} \ No newline at end of file