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
27 changes: 27 additions & 0 deletions JavaFinalProject.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,35 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" exported="">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
18 changes: 16 additions & 2 deletions src/com/generation/model/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ public class Student

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

public void enrollToCourse( Course course )
{
if(isAttendingCourse(course.getCode())) {

System.out.println("You are already enrolled in course.");
}
else {

courses.add(course);
}
//TODO implement this method

}

public void registerApprovedCourse( Course course )
Expand All @@ -34,6 +43,11 @@ public void registerApprovedCourse( Course course )

public boolean isAttendingCourse( String courseCode )
{
for (Course course : courses) {
if (course.getCode().equals(courseCode)) {
return true;
}
}
//TODO implement this method
return false;
}
Expand All @@ -47,6 +61,6 @@ public double getAverage()
@Override
public String toString()
{
return "Student {" + super.toString() + "}";
return "Student {" + super.toString() + " , "+courses.toString()+"}";
}
}
5 changes: 5 additions & 0 deletions src/com/generation/service/StudentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public Student findStudent( String studentId )

public void showSummary()
{
System.out.println("Students: ");
for (Student student: students.values()){

System.out.println(student.toString());
}
//TODO implement
}

Expand Down
17 changes: 14 additions & 3 deletions src/com/generation/utils/PrinterHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,21 @@ 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");
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());
boolean validDate = false;
Date birthDate = null;
while(!validDate){
System.out.println("Enter student birth date (MM/dd/yyyy)!");
try{
birthDate = formatter.parse( scanner.next());
validDate = true;
} catch (ParseException e){
System.out.println("Invalid Date!");
}
};

System.out.println( "|-------------------------------------|" );
Student student = new Student( id, name, email, birthDate );
System.out.println( "Student Successfully Registered! " );
Expand Down
42 changes: 42 additions & 0 deletions test/com/generation/service/CourseServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.generation.service;

import com.generation.model.Course;
import com.generation.model.Module;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.concurrent.Callable;

import static org.junit.jupiter.api.Assertions.*;

class CourseServiceTest {

public CourseService courseService;

@BeforeEach
void setUp() {
courseService = new CourseService();

}

@Test
void getCourseNull() {
Course course1 = courseService.getCourse("0");
assertEquals(null, course1 );

}


@Test
void registerCourse() {
Module module = new Module( "INTRO-CS", "Introduction to Computer Science",
"Introductory module for the generation technical programs" );
Course course1 = new Course( "INTRO-CS-5", "Terminal Fundamentals", 9, module );
courseService.registerCourse(course1);
Course course2 = courseService.getCourse("INTRO-CS-5");
assertEquals(course1, course2);

}
}


38 changes: 38 additions & 0 deletions test/com/generation/service/StudentServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.generation.service;

import com.generation.model.Student;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;

import javax.xml.namespace.QName;

import java.util.Date;

import static org.junit.jupiter.api.Assertions.*;

class StudentServiceTest {

public StudentService studentService;

@BeforeEach
void setUp() {
studentService = new StudentService();
}

@org.junit.jupiter.api.Test
void subscribeStudent() {
Student stud = new Student("1", "Alem", "doch@gmail", new Date());
studentService.subscribeStudent(stud);
Student stud2 = studentService.findStudent("1");
assertEquals(stud, stud2);
}

@org.junit.jupiter.api.Test
void findStudent() {
Student stud = studentService.findStudent("0");
assertEquals(null, stud);
}
}