diff --git a/src/com/generation/model/Student.java b/src/com/generation/model/Student.java index 0897ebe..d3d117e 100644 --- a/src/com/generation/model/Student.java +++ b/src/com/generation/model/Student.java @@ -8,34 +8,43 @@ public class Student extends Person - implements Evaluation -{ + implements Evaluation { private double average; private final List courses = new ArrayList<>(); private final Map approvedCourses = new HashMap<>(); - public Student( String id, String name, String email, Date birthDate ) - { - super( id, name, email, birthDate ); + 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 + { + if (!isAttendingCourse(course.getCode())) { + courses.add(course); + } + } } - public void registerApprovedCourse( Course course ) - { - approvedCourses.put( course.getCode(), course ); + public void registerApprovedCourse(Course course) { + approvedCourses.put(course.getCode(), course); } - public boolean isAttendingCourse( String courseCode ) + public boolean isAttendingCourse(String courseCode) + //return true if course code corresponds to a course in + //--course.java + //need a loop?? enhanced for loop + { //TODO implement this method - return false; +for(Course content : courses){ + if(content.getCode().equals(courseCode)) { + return true; + } +} return false; } @Override diff --git a/src/com/generation/service/CourseService.java b/src/com/generation/service/CourseService.java index 24df98b..7fdbe78 100644 --- a/src/com/generation/service/CourseService.java +++ b/src/com/generation/service/CourseService.java @@ -75,7 +75,7 @@ public void showEnrolledStudents( String courseId ) } } - +//show summary of students enrolled in a course public void showSummary() { System.out.println( "Available Courses:" ); diff --git a/src/com/generation/service/StudentService.java b/src/com/generation/service/StudentService.java index f980e40..f581dd5 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 @@ -25,10 +26,30 @@ public Student findStudent( String studentId ) } public void showSummary() + //find all usages of showSummary method to see where + //--it's being used -- right-click on showSummary, find usages + //needs to do the same thing as the courseService class -- EXAMPLE BELOW +//show summary of enrolled students + //................................................ { - //TODO implement - } - + System.out.println("Student Roster:"); + for (String key : students.keySet()) { + Student student = students.get(key); + System.out.println(student); + } +//this part not working + System.out.println( "Enrolled to Course" ); +// for ( String key : students.keySet() ) +// { +// List courses = enrollToCourse.get( key ); +// System.out.println( "Enrolled in course " + key + ": " ); +// for ( Course course : courses ) +// { +// System.out.println( course ); +// } +// } + } +// ................................................. 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..d02bef6 100644 --- a/src/com/generation/utils/PrinterHelper.java +++ b/src/com/generation/utils/PrinterHelper.java @@ -26,26 +26,36 @@ public static void showMainMenu(){ } 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: |" ); + 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! " ); + //need catch statement to handle the error -- prompt the user to re-enter the info + //can write some code to handle proper date range -- not required + //Is this where this goes??? + boolean validDate = false; + Date birthDate = null; + while(!validDate){ + try { + birthDate = formatter.parse(scanner.next()); + validDate = true; + } catch (ParseException e) { + System.out.println("Please enter a valid date"); + } + } + System.out.println("|-------------------------------------|"); + Student student = new Student(id, name, email, birthDate); + System.out.println("Student Successfully Registered! "); System.out.println(student); return student; } - }