diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..c2621b8
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..df5f35d
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/src/com/generation/Main.java b/src/com/generation/Main.java
index 9e24556..2f4b163 100644
--- a/src/com/generation/Main.java
+++ b/src/com/generation/Main.java
@@ -7,6 +7,7 @@
import com.generation.utils.PrinterHelper;
import java.text.ParseException;
+import java.util.Date;
import java.util.Scanner;
public class Main
@@ -104,4 +105,10 @@ private static void registerStudent( StudentService studentService, Scanner scan
Student student = PrinterHelper.createStudentMenu( scanner );
studentService.subscribeStudent( student );
}
+
+ Student myStudent = new Student("1", "Jane Dow", "again@email.com", new java.util.Date("1995-1-1"));
+ StudentService myStudentService = new StudentService();
+
+
+
}
diff --git a/src/com/generation/model/Student.java b/src/com/generation/model/Student.java
index 0897ebe..3d39cc2 100644
--- a/src/com/generation/model/Student.java
+++ b/src/com/generation/model/Student.java
@@ -24,6 +24,12 @@ public Student( String id, String name, String email, Date birthDate )
public void enrollToCourse( Course course )
{
//TODO implement this method
+ //to add courses to the list Course
+ if(!isAttendingCourse(course.getCode())) {
+ this.courses.add(course); }
+ else {
+ System.out.println("The Student is already enrolled in the course.");
+ }
}
public void registerApprovedCourse( Course course )
@@ -32,12 +38,23 @@ public void registerApprovedCourse( Course course )
}
- public boolean isAttendingCourse( String courseCode )
- {
+ public boolean isAttendingCourse( String courseCode ) {
+
//TODO implement this method
+
+ for (Course course : courses) {
+ if (course.getCode().equals(courseCode)) {
+ return true;
+ }
+ }
return false;
}
+ //return true if the courseCode correspond to any course on the List,
+ // go to the Course class, use the loop, if it matches - return true;
+
+
+
@Override
public double getAverage()
{
diff --git a/src/com/generation/service/StudentService.java b/src/com/generation/service/StudentService.java
index f980e40..08c878f 100644
--- a/src/com/generation/service/StudentService.java
+++ b/src/com/generation/service/StudentService.java
@@ -3,13 +3,16 @@
import com.generation.model.Course;
import com.generation.model.Student;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
public class StudentService
{
private final Map students = new HashMap<>();
+
public void subscribeStudent( Student student )
{
students.put( student.getId(), student );
@@ -26,7 +29,14 @@ public Student findStudent( String studentId )
public void showSummary()
{
- //TODO implement
+ // shows the list of all students;
+ System.out.println("Students: ");
+ for (Student student : students.values()) {
+ System.out.println(student.toString());
+ }
+ //or
+ // System.out.println(List.of(students));
+
}
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..179aa20 100644
--- a/src/com/generation/utils/PrinterHelper.java
+++ b/src/com/generation/utils/PrinterHelper.java
@@ -38,10 +38,21 @@ 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");
+ 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( "|-------------------------------------|" );
+ boolean validDate = false;
+ Date birthDate = null;
+ while(!validDate) {
+ System.out.println("|Please Enter the valid date!|");
+ try {
+ birthDate = formatter.parse( scanner.next());
+ validDate = true; }
+ catch(Exception e) {
+ System.out.println("Please Enter the valid date!");
+ }
+ }
+ System.out.println("|------------------------------------|");
+
Student student = new Student( id, name, email, birthDate );
System.out.println( "Student Successfully Registered! " );
System.out.println(student);