diff --git a/JavaFinalProject.iml b/JavaFinalProject.iml
index c90834f..d8eaf0e 100644
--- a/JavaFinalProject.iml
+++ b/JavaFinalProject.iml
@@ -4,8 +4,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/com/generation/model/Student.java b/src/com/generation/model/Student.java
index 0897ebe..10091a8 100644
--- a/src/com/generation/model/Student.java
+++ b/src/com/generation/model/Student.java
@@ -18,12 +18,21 @@ public class Student
public Student( String id, String name, String email, Date birthDate )
{
- super( id, name, email, birthDate );
+ super( id, name, email, birthDate);
}
public void enrollToCourse( Course course )
{
+ if(isAttendingCourse(course.getCode())) {
+
+ System.out.println("You are already enrolled in course.");
+ }
+ else {
+
+ courses.add(course);
+ }
//TODO implement this method
+
}
public void registerApprovedCourse( Course course )
@@ -34,6 +43,11 @@ public void registerApprovedCourse( Course course )
public boolean isAttendingCourse( String courseCode )
{
+ for (Course course : courses) {
+ if (course.getCode().equals(courseCode)) {
+ return true;
+ }
+ }
//TODO implement this method
return false;
}
@@ -47,6 +61,6 @@ public double getAverage()
@Override
public String toString()
{
- return "Student {" + super.toString() + "}";
+ return "Student {" + super.toString() + " , "+courses.toString()+"}";
}
}
diff --git a/src/com/generation/service/StudentService.java b/src/com/generation/service/StudentService.java
index f980e40..d8158bd 100644
--- a/src/com/generation/service/StudentService.java
+++ b/src/com/generation/service/StudentService.java
@@ -26,6 +26,11 @@ public Student findStudent( String studentId )
public void showSummary()
{
+ System.out.println("Students: ");
+ for (Student student: students.values()){
+
+ System.out.println(student.toString());
+ }
//TODO implement
}
diff --git a/src/com/generation/utils/PrinterHelper.java b/src/com/generation/utils/PrinterHelper.java
index 6f1ca9b..265f5ca 100644
--- a/src/com/generation/utils/PrinterHelper.java
+++ b/src/com/generation/utils/PrinterHelper.java
@@ -37,10 +37,21 @@ 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");
+ 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());
+ boolean validDate = false;
+ Date birthDate = null;
+ 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("Invalid 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..d2c81ec
--- /dev/null
+++ b/test/com/generation/service/CourseServiceTest.java
@@ -0,0 +1,42 @@
+package com.generation.service;
+
+import com.generation.model.Course;
+import com.generation.model.Module;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.Callable;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class CourseServiceTest {
+
+ public CourseService courseService;
+
+ @BeforeEach
+ void setUp() {
+ courseService = new CourseService();
+
+ }
+
+ @Test
+ void getCourseNull() {
+ Course course1 = courseService.getCourse("0");
+ assertEquals(null, course1 );
+
+ }
+
+
+ @Test
+ void registerCourse() {
+ Module module = new Module( "INTRO-CS", "Introduction to Computer Science",
+ "Introductory module for the generation technical programs" );
+ Course course1 = new Course( "INTRO-CS-5", "Terminal Fundamentals", 9, module );
+ courseService.registerCourse(course1);
+ Course course2 = courseService.getCourse("INTRO-CS-5");
+ assertEquals(course1, course2);
+
+ }
+ }
+
+
diff --git a/test/com/generation/service/StudentServiceTest.java b/test/com/generation/service/StudentServiceTest.java
new file mode 100644
index 0000000..af87a5d
--- /dev/null
+++ b/test/com/generation/service/StudentServiceTest.java
@@ -0,0 +1,38 @@
+package com.generation.service;
+
+import com.generation.model.Student;
+import org.junit.Before;
+import org.junit.jupiter.api.BeforeEach;
+
+import javax.xml.namespace.QName;
+
+import java.util.Date;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class StudentServiceTest {
+
+ public StudentService studentService;
+
+ @BeforeEach
+ void setUp() {
+ studentService = new StudentService();
+ }
+
+ @org.junit.jupiter.api.Test
+ void subscribeStudent() {
+ Student stud = new Student("1", "Alem", "doch@gmail", new Date());
+ studentService.subscribeStudent(stud);
+ Student stud2 = studentService.findStudent("1");
+ assertEquals(stud, stud2);
+ }
+
+ @org.junit.jupiter.api.Test
+ void findStudent() {
+ Student stud = studentService.findStudent("0");
+ assertEquals(null, stud);
+ }
+}
+
+
+