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
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/com/generation/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ private static void showCoursesSummary( CourseService courseService, Scanner sca

private static void showStudentsSummary( StudentService studentService, Scanner scanner )
{
studentService.showSummary();
String key = null;
studentService.showSummary(key);
}

private static void findStudent( StudentService studentService, Scanner scanner )
Expand Down
32 changes: 28 additions & 4 deletions src/com/generation/model/Student.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.generation.model;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -13,17 +14,33 @@ public class Student
private double average;

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

//Student class instance field courses assigned to a new array list
private final Map<String, Course> approvedCourses = new HashMap<>();
private Course course;

public Student( String id, String name, String email, Date birthDate )
{
super( id, name, email, birthDate );
}

public void enrollToCourse( Course course )
public Course getCourse() {
return course;
}

public void setCourse(Course course) {
this.course = course;
}

public void enrollToCourse(Course course )
{
//TODO implement this method
if (!isAttendingCourse(course.getCode())) {
courses.add(course);
}
else {
System.out.println("Student previously enrolled in course, enter different course.");
}
//Method that will add course objects to the instance field courses from above array list.
// Implementing conditional statement to prevent double enrollment with else sout message
}

public void registerApprovedCourse( Course course )
Expand All @@ -34,8 +51,15 @@ public void registerApprovedCourse( Course course )

public boolean isAttendingCourse( String courseCode )
{
//TODO implement this method
for (Course c : courses) {
if (c.getCode().equals(courseCode)) {
return true;
}
}
return false;
//Boolean method that will return true if parameter courseCode is true for student with the argument that will be passed into it
//Create enhanced for loop/for each loop that will loop over entry of courses from courses instance field array list above
//Getting code of Course c to check if it equals to the argument that was passed to courseCode parameter
}

@Override
Expand Down
25 changes: 24 additions & 1 deletion src/com/generation/service/StudentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ public Student findStudent( String studentId )
return null;
}

public void showSummary()
public void showSummary(String key)
{
System.out.println("Students: ");
for (Student s: students.values()) {
Student stud = students.get(key);
System.out.println(s.toString());
}
//TODO implement
}

Expand All @@ -39,3 +44,21 @@ public void enrollToCourse( String studentId, Course course )


}



// System.out.println( "Available Courses:" );
// for ( String key : courses.keySet() )
// {
// Course course = courses.get( key );
// System.out.println( course );
// }
// System.out.println( "Enrolled Students" );
// for ( String key : enrolledStudents.keySet() )
// {
// List<Student> students = enrolledStudents.get( key );
// System.out.println( "Students on Course " + key + ": " );
// for ( Student student : students )
// {
// System.out.println( student );
// }
22 changes: 16 additions & 6 deletions src/com/generation/utils/PrinterHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
public class PrinterHelper
{

private static Date birthDate;

public static void showMainMenu(){
System.out.println( "|-------------------------------|" );
System.out.println( "| Welcome to StudentGen |" );
Expand All @@ -37,15 +39,23 @@ public static Student createStudentMenu( Scanner scanner )
String id = scanner.next();
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");
//TODO validate date format and catch exception to avoid crash
Date birthDate = formatter.parse( scanner.next());
DateFormat formatter = new SimpleDateFormat( "MM/dd/yyyy");
boolean validDate = false;
Date birthdate = null;
while (!validDate) {
System.out.println("| Enter birthdate in following format (mm/dd/yy) |");
try {
birthdate = formatter.parse(scanner.next());
validDate= true;
} catch (ParseException error) {
System.out.println("Invalid birthdate!");
}
} ;
// While loop with try and catch statement to catch wrong birthdate input
System.out.println( "|-------------------------------------|" );
Student student = new Student( id, name, email, birthDate );
Student student = new Student( id, name, email, birthdate );
System.out.println( "Student Successfully Registered! " );
System.out.println(student);
return student;
}

}