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
1 change: 1 addition & 0 deletions JavaFinalProject.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
9 changes: 6 additions & 3 deletions src/com/generation/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import com.generation.service.StudentService;
import com.generation.utils.PrinterHelper;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main
Expand All @@ -17,16 +20,16 @@ public static void main( String[] args )
{
StudentService studentService = new StudentService();
CourseService courseService = new CourseService();
Scanner scanner = new Scanner( System.in );
Scanner scanner = new Scanner(System.in);
int option = 0;
do
{
PrinterHelper.showMainMenu();
option = scanner.nextInt();
switch ( option )
switch(option)
{
case 1:
registerStudent( studentService, scanner );
registerStudent(studentService, scanner);
break;
case 2:
findStudent( studentService, scanner );
Expand Down
25 changes: 23 additions & 2 deletions src/com/generation/model/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Student
extends Person
implements Evaluation
{

private double average;

private final List<Course> courses = new ArrayList<>();
Expand All @@ -21,9 +22,16 @@ 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
//implemented if statement after class demo
if(!isAttendingCourse(course.getCode())){
courses.add(course);
System.out.println("Student has successful been enrolled");
} else {
System.out.println("Student is already enrolled");
}
}

public void registerApprovedCourse( Course course )
Expand All @@ -32,9 +40,21 @@ public void registerApprovedCourse( Course course )
}


public boolean isAttendingCourse( String courseCode )
public boolean isAttendingCourse(String courseCode)
{
// for(Course course: courses) {
// if(course.getCode().equals(courseCode) {
// return true;
// }
// }
// return false;

//TODO implement this method
for(int i = 0; i < courses.size(); i++) {
if(courses.get(i).getCode() == courseCode) {
return true;
}
}
return false;
}

Expand All @@ -49,4 +69,5 @@ public String toString()
{
return "Student {" + super.toString() + "}";
}

}
8 changes: 7 additions & 1 deletion src/com/generation/service/StudentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ public Student findStudent( String studentId )
public void showSummary()
{
//TODO implement
System.out.println("Student Summary: ");
// Answer based on class demo
for(Student summary: students.values()) {
Student student = students.get(summary);
System.out.println(summary.toString());
}
}

public void enrollToCourse( String studentId, Course course )
{
if ( students.containsKey( studentId ) )
{
students.get( studentId ).enrollToCourse( course );
students.get(studentId).enrollToCourse( course );
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/com/generation/utils/PrinterHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,19 @@ 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");
boolean validDate = false;
DateFormat formatter = new SimpleDateFormat( "MM/dd/yyyy");
//TODO validate date format and catch exception to avoid crash
Date birthDate = formatter.parse( scanner.next());
Date birthDate = null;
// while loop -> try & catch
while(!validDate) {
try {
birthDate = formatter.parse( scanner.next());
validDate = true;
} catch (ParseException e) {
System.out.println("Date isn't valid");
}
}
System.out.println( "|-------------------------------------|" );
Student student = new Student( id, name, email, birthDate );
System.out.println( "Student Successfully Registered! " );
Expand Down