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.

17 changes: 17 additions & 0 deletions JavaFinalProject.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@
<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="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>
4 changes: 3 additions & 1 deletion src/com/generation/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ private static void enrollStudentToCourse( StudentService studentService, Course
System.out.println( course );
courseService.enrollStudent( courseId, student );
studentService.enrollToCourse( studentId, course );
System.out.println( "Student with ID: " + studentId + " enrolled successfully to " + courseId );

//System.out.println( "Student with ID: " + studentId + " enrolled successfully to " + courseId );

}

Expand All @@ -91,6 +92,7 @@ private static void findStudent( StudentService studentService, Scanner scanner
{
System.out.println( "Student Found: " );
System.out.println( student );

}
else
{
Expand Down
3 changes: 3 additions & 0 deletions src/com/generation/model/Course.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.generation.model;

import java.util.Objects;

public class Course
{
private final String code;
Expand Down Expand Up @@ -45,4 +47,5 @@ public String toString()
return "Course{" + "code='" + code + '\'' + ", name='" + name + '\'' + ", credits=" + credits + ", module="
+ module + '}';
}

}
31 changes: 24 additions & 7 deletions src/com/generation/model/Student.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.generation.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public class Student
extends Person
Expand All @@ -24,6 +20,13 @@ public Student( String id, String name, String email, Date birthDate )
public void enrollToCourse( Course course )
{
//TODO implement this method
if(! isAttendingCourse(course.getCode())) {
this.courses.add(course);
System.out.println( "Student with ID: " + super.getId() + " enrolled successfully to " + course.getCode() );
}
else{
System.out.println(super.getId() +" already enrolled in course " + course.getCode());
}
}

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


public boolean isAttendingCourse( String courseCode )
// public List<Course> getCourses() {
// return courses;
// }

public Map<String, Course> getApprovedCourses() {
return approvedCourses;
}

public boolean isAttendingCourse(String courseCode )
{
//TODO implement this method
for(Course courseList : courses) {
if(Objects.equals(courseList.getCode(), courseCode)){
System.out.println("Already attending course ");
return true;
}
}
return false;
}

Expand All @@ -47,6 +64,6 @@ public double getAverage()
@Override
public String toString()
{
return "Student {" + super.toString() + "}";
return "Student {" + super.toString() + ","+ courses.toString() +"}";
}
}
7 changes: 3 additions & 4 deletions src/com/generation/service/CourseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.generation.model.Module;
import com.generation.model.Student;

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

public class CourseService
{
Expand Down Expand Up @@ -95,4 +92,6 @@ public void showSummary()
}
}
}


}
27 changes: 25 additions & 2 deletions src/com/generation/service/StudentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.generation.model.Course;
import com.generation.model.Student;

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

public class StudentService
Expand All @@ -24,9 +26,27 @@ public Student findStudent( String studentId )
return null;
}

public void showSummary()
{
public void showSummary() {
//TODO implement
System.out.println("Students Summary:");

for (Student student: students.values() ){
System.out.println(student.toString());
}
// Another way of doing, but creating unneccesary objects, method calls and also using the slow arraylist
// for ( String key : students.keySet() )
// {
// Student student = students.get(key);
// List<Course> courses = student.getCourses();
// ArrayList<String> summary = new ArrayList<>();
// summary.add(student.toString());
// for (Course course:courses) {
// //System.out.print(course.toString()+" ");
// summary.add(course.toString());
// }
// System.out.println(summary.toString());
//
// }
}

public void enrollToCourse( String studentId, Course course )
Expand All @@ -37,5 +57,8 @@ public void enrollToCourse( String studentId, Course course )
}
}

public Map<String, Student> getStudents() {
return students;
}

}
15 changes: 12 additions & 3 deletions src/com/generation/utils/PrinterHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ 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());
Date birthDate =null;
do {
System.out.println("| Enter student birth date(mm/dd/yyyy)|");
try {
birthDate = formatter.parse(scanner.next());
} catch (ParseException e) {
System.err.println("Birth date entered in wrong format");
}
}while(birthDate == null);

System.out.println( "|-------------------------------------|" );
Student student = new Student( id, name, email, birthDate );
System.out.println( "Student Successfully Registered! " );
Expand Down
37 changes: 37 additions & 0 deletions test/com/generation/service/CourseServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.generation.service;
import com.generation.model.Course;
import com.generation.model.Module;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

class CourseServiceTest {

CourseService courseService = new CourseService();

@Test
void getCourse() {
Module module = new Module( "INTRO-CS", "Introduction to Computer Science",
"Introductory module for the generation technical programs" );
Course course = new Course("INTRO-CS-1", "Introduction to Computer Science", 9, module);
assertEquals(course.toString(), courseService.getCourse("INTRO-CS-1").toString());


}

@Test
void registerCourse() {
Module module = new Module( "INTRO-GD", "Introduction to Gardening",
"Introductory module for the gardening programs" );
Course course = new Course("INTRO-GD-1", "Introduction to soil prepping", 9, module);
courseService.registerCourse(course);
assertEquals(course, courseService.getCourse("INTRO-GD-1"));
}

// you can write your own test methods and those methods needn't be there in your .java file
@Test
void getCourseNull() {

assertEquals(null, courseService.getCourse("some course that is not offered"));
}

}
39 changes: 39 additions & 0 deletions test/com/generation/service/StudentServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.generation.service;
import com.generation.model.Student;
import org.junit.jupiter.api.Test;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;

class StudentServiceTest {
StudentService studentService = new StudentService();
Student student1 = new Student("1","Tom","tom@abc.com",new Date(11/11/1111));
Student student2 = new Student("2","Harry","harry@abc.com",new Date(11/11/1111));

//
@Test
void findStudent() {
studentService.subscribeStudent(student1);
assertEquals(student1,studentService.findStudent("1"));
}

@Test
void getStudents() {
Map<String, Student> students = new HashMap<>();
students.put("1", student1);
students.put("2", student2);

studentService.subscribeStudent(student1);
studentService.subscribeStudent(student2);
assertEquals(students,studentService.getStudents());

}
@Test
void findStudentNull() {

assertEquals(null,studentService.findStudent(""));
}


}