diff --git a/JavaFinalProject.iml b/JavaFinalProject.iml
index c90834f..5e9351f 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..5f46159 100644
--- a/src/com/generation/model/Student.java
+++ b/src/com/generation/model/Student.java
@@ -23,7 +23,7 @@ public Student( String id, String name, String email, Date birthDate )
public void enrollToCourse( Course course )
{
- //TODO implement this method
+ courses.add(course);
}
public void registerApprovedCourse( Course course )
@@ -33,13 +33,26 @@ public void registerApprovedCourse( Course course )
public boolean isAttendingCourse( String courseCode )
- {
- //TODO implement this method
+ { //TODO implement this method
+ //iterate Course object from arrayList of courses
+ //arrayList(courses) for each method
+
+ for(Course course:courses) {
+ //in the arrayList use getCode method
+ //to check if it matches with the user's input(courseCode) use .equals
+ if (course.getCode().equals(courseCode)) {
+ //if it equals return true
+ return true;
+ } else {
+ //if not equals return false
+ return false;
+ }
+ }
return false;
+
}
- @Override
- public double getAverage()
+ public double getAverage()
{
return average;
}
diff --git a/src/com/generation/service/CourseService.java b/src/com/generation/service/CourseService.java
index 24df98b..629cf56 100644
--- a/src/com/generation/service/CourseService.java
+++ b/src/com/generation/service/CourseService.java
@@ -49,6 +49,7 @@ public Course getCourse( String code )
{
if ( courses.containsKey( code ) )
{
+ // input course code
return courses.get( code );
}
return null;
diff --git a/src/com/generation/service/CourseServiceTest.java b/src/com/generation/service/CourseServiceTest.java
new file mode 100644
index 0000000..aba04a7
--- /dev/null
+++ b/src/com/generation/service/CourseServiceTest.java
@@ -0,0 +1,33 @@
+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 static org.junit.jupiter.api.Assertions.*;
+
+class CourseServiceTest {
+ // import object from CourseService
+ public CourseService courseService;
+ // before each test implement this constructor
+ @BeforeEach
+ void setUp() {
+ courseService = new CourseService(); }
+
+ @Test
+ void getCourseNull() {
+ Course course = courseService.getCourse("Invalid Code");
+ assertNull(course);
+ }
+
+ @Test
+ void registerCourse() {
+ Module moduleWebFundamentals = new Module("INTRO-WEB", "Web Development Fundamentals",
+ "Introduction to fundamentals of web development" );
+ Course course = new Course("INTRO-WEB-7", "Introduction to JavaScript for Web Development", 9, moduleWebFundamentals );
+ courseService.registerCourse(course);
+ Course course1 = courseService.getCourse("INTRO-WEB-7");
+ assertEquals(course, course1);
+ }
+}
\ No newline at end of file
diff --git a/src/com/generation/service/StudentService.java b/src/com/generation/service/StudentService.java
index f980e40..33466a7 100644
--- a/src/com/generation/service/StudentService.java
+++ b/src/com/generation/service/StudentService.java
@@ -26,9 +26,17 @@ public Student findStudent( String studentId )
public void showSummary()
{
- //TODO implement
+ // implement students values to showSummary
+ System.out.println( "Students: ");
+ for (Student student : students.values())
+ {
+ System.out.println(student.toString());
+
+ }
}
+
+ // implement students id into enrollToCourse
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..533b95d
--- /dev/null
+++ b/src/com/generation/service/StudentServiceTest.java
@@ -0,0 +1,37 @@
+package com.generation.service;
+
+import com.generation.model.Course;
+import com.generation.model.Module;
+import com.generation.model.Student;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class StudentServiceTest {
+ // import object from StudentService
+ public StudentService studentService() {
+ return null;
+ }
+
+ // before each test implement
+ @BeforeEach
+ void setUp() {
+ StudentService StudentService = new StudentService();
+ }
+
+ @org.junit.jupiter.api.Test
+ void showStudentSummary() {
+ StudentService studentService = new StudentService();
+ studentService.showSummary();
+ }
+
+ @org.junit.jupiter.api.Test
+ void enrollToCourse() {
+ StudentService studentService = new StudentService();
+ Module module;
+ studentService.enrollToCourse("1", new Course( "INTRO-CS-2", "Introduction to Algorithms",
+ 9, new Module("INTRO-CS", "Introduction to Computer Science",
+ "Introductory module for the generation technical programs")));
+ }
+}
\ No newline at end of file
diff --git a/src/com/generation/utils/PrinterHelper.java b/src/com/generation/utils/PrinterHelper.java
index 6f1ca9b..ea7a753 100644
--- a/src/com/generation/utils/PrinterHelper.java
+++ b/src/com/generation/utils/PrinterHelper.java
@@ -2,50 +2,69 @@
import com.generation.model.Student;
+import java.sql.SQLOutput;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
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");
- //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! " );
- System.out.println(student);
- return student;
+ System.out.println("| Enter student birth date(mm/dd/yyyy)|");
+
+ // format set date as MM/dd/yyyy
+ DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
+ // input student's date of birth
+ boolean toValidDate = false;
+ Date birthDate = null;
+
+ /* TODO validate date format and catch exception to avoid crash */
+
+ // input try...catch and return exception
+ while(!toValidDate) {
+
+
+ try {
+ birthDate = formatter.parse(scanner.next());
+ toValidDate = true;
+ } catch (ParseException e) {
+ System.out.println("Invalid Date!");
+ System.out.println("| Enter valid date format (mm/dd/yyyy)|");
+ }
+ }
+ System.out.println("|-------------------------------------|");
+ Student student = new Student(id, name, email, birthDate);
+ System.out.println("Student Successfully Registered! ");
+ System.out.println(student);
+ return student;
+
+ }
}
-}
+