From 0d4823dfa0ebad5cb6a7e5fe5b120848de33e813 Mon Sep 17 00:00:00 2001 From: NSRoberts Date: Tue, 29 Nov 2022 10:10:42 -0700 Subject: [PATCH 1/3] First commit. Finishing showSummary and fixing other pieces. --- src/com/generation/model/Student.java | 16 ++++++++-- src/com/generation/service/CourseService.java | 2 +- .../generation/service/StudentService.java | 29 ++++++++++++++++++- src/com/generation/utils/PrinterHelper.java | 3 ++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/com/generation/model/Student.java b/src/com/generation/model/Student.java index 0897ebe..c6dfb25 100644 --- a/src/com/generation/model/Student.java +++ b/src/com/generation/model/Student.java @@ -24,8 +24,10 @@ public Student( String id, String name, String email, Date birthDate ) public void enrollToCourse( Course course ) { //TODO implement this method +//not understanding how to write this + .put( course.getCode(), course ); } - +// public void registerApprovedCourse( Course course ) { approvedCourses.put( course.getCode(), course ); @@ -33,9 +35,19 @@ public void registerApprovedCourse( Course course ) public boolean isAttendingCourse( String courseCode ) + //return true if course code corresponds to a course in + //--course.java + //need a loop?? + //not understanding how to write this { + //TODO implement this method - return false; + if ( students.containsKey( courseId ) ) + { + students.put( courseId, new ArrayList<>() ); + } + students.get( courseId ).add( student ); + 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..e33b077 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,9 +26,35 @@ 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 + //................................................ +//Yay!! 9:16pm - small piece figured out! { + 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 ); + } + } + } +// ................................................. + //TODO implement - } + + 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..7ea237b 100644 --- a/src/com/generation/utils/PrinterHelper.java +++ b/src/com/generation/utils/PrinterHelper.java @@ -40,6 +40,9 @@ public static Student createStudentMenu( Scanner scanner ) 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 + //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??? Date birthDate = formatter.parse( scanner.next()); System.out.println( "|-------------------------------------|" ); Student student = new Student( id, name, email, birthDate ); From a384a630db5c19f5e62098725eb919f7fd1210d5 Mon Sep 17 00:00:00 2001 From: NSRoberts Date: Tue, 29 Nov 2022 11:34:44 -0700 Subject: [PATCH 2/3] Worked out date and working on student service to read the course. --- src/com/generation/model/Student.java | 44 +++++++++---------- .../generation/service/StudentService.java | 20 ++++----- src/com/generation/utils/PrinterHelper.java | 37 +++++++++------- 3 files changed, 53 insertions(+), 48 deletions(-) diff --git a/src/com/generation/model/Student.java b/src/com/generation/model/Student.java index c6dfb25..f1d5d99 100644 --- a/src/com/generation/model/Student.java +++ b/src/com/generation/model/Student.java @@ -8,48 +8,46 @@ 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 //not understanding how to write this - .put( course.getCode(), course ); + { + 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 ) - //return true if course code corresponds to a course in - //--course.java - //need a loop?? - //not understanding how to write this + public boolean isAttendingCourse(String courseCode) + //return true if course code corresponds to a course in + //--course.java + //need a loop?? + //not understanding how to write this { //TODO implement this method - if ( students.containsKey( courseId ) ) - { - students.put( courseId, new ArrayList<>() ); - } - students.get( courseId ).add( student ); - return false; + + return false; } + + @Override public double getAverage() { diff --git a/src/com/generation/service/StudentService.java b/src/com/generation/service/StudentService.java index e33b077..1398271 100644 --- a/src/com/generation/service/StudentService.java +++ b/src/com/generation/service/StudentService.java @@ -40,19 +40,19 @@ public void showSummary() } //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 ); - } - } +// 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 ); +// } +// } } // ................................................. - //TODO implement + diff --git a/src/com/generation/utils/PrinterHelper.java b/src/com/generation/utils/PrinterHelper.java index 7ea237b..d02bef6 100644 --- a/src/com/generation/utils/PrinterHelper.java +++ b/src/com/generation/utils/PrinterHelper.java @@ -26,29 +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 //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??? - Date birthDate = formatter.parse( scanner.next()); - System.out.println( "|-------------------------------------|" ); - Student student = new Student( id, name, email, birthDate ); - System.out.println( "Student Successfully Registered! " ); + 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; } - } From 4512feb12858a1398148069dadb13639f9afb437 Mon Sep 17 00:00:00 2001 From: NSRoberts Date: Tue, 29 Nov 2022 11:55:49 -0700 Subject: [PATCH 3/3] Unable to get show summary to reflect the course for students. --- src/com/generation/model/Student.java | 15 +++++++-------- src/com/generation/service/StudentService.java | 6 ------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/com/generation/model/Student.java b/src/com/generation/model/Student.java index f1d5d99..d3d117e 100644 --- a/src/com/generation/model/Student.java +++ b/src/com/generation/model/Student.java @@ -21,7 +21,6 @@ public Student(String id, String name, String email, Date birthDate) { public void enrollToCourse(Course course) { //TODO implement this method -//not understanding how to write this { if (!isAttendingCourse(course.getCode())) { courses.add(course); @@ -37,16 +36,16 @@ public void registerApprovedCourse(Course course) { public boolean isAttendingCourse(String courseCode) //return true if course code corresponds to a course in //--course.java - //need a loop?? - //not understanding how to write this - { + //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 public double getAverage() diff --git a/src/com/generation/service/StudentService.java b/src/com/generation/service/StudentService.java index 1398271..f581dd5 100644 --- a/src/com/generation/service/StudentService.java +++ b/src/com/generation/service/StudentService.java @@ -31,7 +31,6 @@ public void showSummary() //needs to do the same thing as the courseService class -- EXAMPLE BELOW //show summary of enrolled students //................................................ -//Yay!! 9:16pm - small piece figured out! { System.out.println("Student Roster:"); for (String key : students.keySet()) { @@ -51,11 +50,6 @@ public void showSummary() // } } // ................................................. - - - - - public void enrollToCourse( String studentId, Course course ) { if ( students.containsKey( studentId ) )