Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/com/generation/model/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,43 @@

public class Student
extends Person
implements Evaluation
{
implements Evaluation {
private double average;

private final List<Course> courses = new ArrayList<>();

private final Map<String, Course> 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
Expand Down
2 changes: 1 addition & 1 deletion src/com/generation/service/CourseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:" );
Expand Down
27 changes: 24 additions & 3 deletions src/com/generation/service/StudentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.generation.model.Student;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StudentService
Expand All @@ -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<Course> 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 ) )
Expand Down
40 changes: 25 additions & 15 deletions src/com/generation/utils/PrinterHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}