diff --git a/JavaFinalProject.iml b/JavaFinalProject.iml index c90834f..861e104 100644 --- a/JavaFinalProject.iml +++ b/JavaFinalProject.iml @@ -4,6 +4,7 @@ + diff --git a/src/com/generation/Main.java b/src/com/generation/Main.java index 9e24556..0d3d3b5 100644 --- a/src/com/generation/Main.java +++ b/src/com/generation/Main.java @@ -6,7 +6,10 @@ import com.generation.service.StudentService; import com.generation.utils.PrinterHelper; +import java.text.DateFormat; import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Scanner; public class Main @@ -17,16 +20,16 @@ public static void main( String[] args ) { StudentService studentService = new StudentService(); CourseService courseService = new CourseService(); - Scanner scanner = new Scanner( System.in ); + Scanner scanner = new Scanner(System.in); int option = 0; do { PrinterHelper.showMainMenu(); option = scanner.nextInt(); - switch ( option ) + switch(option) { case 1: - registerStudent( studentService, scanner ); + registerStudent(studentService, scanner); break; case 2: findStudent( studentService, scanner ); diff --git a/src/com/generation/model/Student.java b/src/com/generation/model/Student.java index 0897ebe..94c1ef3 100644 --- a/src/com/generation/model/Student.java +++ b/src/com/generation/model/Student.java @@ -10,6 +10,7 @@ public class Student extends Person implements Evaluation { + private double average; private final List courses = new ArrayList<>(); @@ -21,9 +22,16 @@ public Student( String id, String name, String email, Date birthDate ) super( id, name, email, birthDate ); } - public void enrollToCourse( Course course ) + public void enrollToCourse(Course course) { //TODO implement this method + //implemented if statement after class demo + if(!isAttendingCourse(course.getCode())){ + courses.add(course); + System.out.println("Student has successful been enrolled"); + } else { + System.out.println("Student is already enrolled"); + } } public void registerApprovedCourse( Course course ) @@ -32,9 +40,21 @@ public void registerApprovedCourse( Course course ) } - public boolean isAttendingCourse( String courseCode ) + public boolean isAttendingCourse(String courseCode) { +// for(Course course: courses) { +// if(course.getCode().equals(courseCode) { +// return true; +// } +// } +// return false; + //TODO implement this method + for(int i = 0; i < courses.size(); i++) { + if(courses.get(i).getCode() == courseCode) { + return true; + } + } return false; } @@ -49,4 +69,5 @@ public String toString() { return "Student {" + super.toString() + "}"; } + } diff --git a/src/com/generation/service/StudentService.java b/src/com/generation/service/StudentService.java index f980e40..e67f9b4 100644 --- a/src/com/generation/service/StudentService.java +++ b/src/com/generation/service/StudentService.java @@ -27,13 +27,19 @@ public Student findStudent( String studentId ) public void showSummary() { //TODO implement + System.out.println("Student Summary: "); + // Answer based on class demo + for(Student summary: students.values()) { + Student student = students.get(summary); + System.out.println(summary.toString()); + } } public void enrollToCourse( String studentId, Course course ) { if ( students.containsKey( studentId ) ) { - students.get( studentId ).enrollToCourse( course ); + students.get(studentId).enrollToCourse( course ); } } diff --git a/src/com/generation/utils/PrinterHelper.java b/src/com/generation/utils/PrinterHelper.java index 6f1ca9b..d998041 100644 --- a/src/com/generation/utils/PrinterHelper.java +++ b/src/com/generation/utils/PrinterHelper.java @@ -38,9 +38,19 @@ 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"); + boolean validDate = false; + 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; + // while loop -> try & catch + while(!validDate) { + try { + birthDate = formatter.parse( scanner.next()); + validDate = true; + } catch (ParseException e) { + System.out.println("Date isn't valid"); + } + } System.out.println( "|-------------------------------------|" ); Student student = new Student( id, name, email, birthDate ); System.out.println( "Student Successfully Registered! " );