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
7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

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

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.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" 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>
1 change: 1 addition & 0 deletions src/com/generation/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void main( String[] args )
while ( option != 6 );
}


private static void enrollStudentToCourse( StudentService studentService, CourseService courseService,
Scanner scanner )
{
Expand Down
2 changes: 1 addition & 1 deletion src/com/generation/model/Instructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Instructor

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

protected Instructor( String id, String name, String email, Date birthDate )
protected Instructor(String id, String name, String email, Date birthDate )
{
super( id, name, email, birthDate );
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/generation/model/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract public class Person

private final Date birthDate;

protected Person( String id, String name, String email, Date birthDate )
protected Person(String id, String name, String email, Date birthDate )
{
this.id = id;
this.name = name;
Expand Down
54 changes: 36 additions & 18 deletions src/com/generation/model/Student.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
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
implements Evaluation
{
private double average;

private final List<Course> courses = new ArrayList<>();
// an array list that holds the objects of Course named:courses
private final List<Course> courses = new ArrayList<>();
//temp holds the courses each student is enrolled
public final List<String> temp = new ArrayList<>();

private final Map<String, Course> approvedCourses = new HashMap<>();

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

//getter method to return the enrolled courses to display in student summary
public List<String> getTemp(){
return temp;
}
public void enrollToCourse( Course course )
{
//TODO implement this method
//check if student is already enrolled in course
if(!isAttendingCourse(course.getCode())) {
//add the user's input course into the arrayList course
courses.add(course);
//add the course into the arrayList
temp.add(String.valueOf(course));
} else {
System.out.println("Student is already enrolled in course");
}
}


public boolean isAttendingCourse( String courseCode ) {
//iterate through the courses arrayList that consists of Course object.
// IE: [Course{Code,Name,Credits,Module},Course{Code,Name,Credits,Module},Course{Code,Name,Credits,Module}]
//for each element(temp) in arrayList(courses)
for (Course temp : courses) {
//use getCode method to get the course code of each element in the arrayList
//.equals check if it matches with the user's input(courseCode)
if (temp.getCode().equals(courseCode)) {
//return true if it equals
return true;
//return false if not found
}
}
return false;
}

public void registerApprovedCourse( Course course )
Expand All @@ -32,12 +56,6 @@ public void registerApprovedCourse( Course course )
}


public boolean isAttendingCourse( String courseCode )
{
//TODO implement this method
return false;
}

@Override
public double getAverage()
{
Expand Down
14 changes: 6 additions & 8 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 @@ -63,7 +60,8 @@ public void enrollStudent( String courseId, Student student )
enrolledStudents.get( courseId ).add( student );
}

public void showEnrolledStudents( String courseId )

public void showEnrolledStudents(String courseId)
{
if ( enrolledStudents.containsKey( courseId ) )
{
Expand All @@ -75,7 +73,6 @@ public void showEnrolledStudents( String courseId )
}
}


public void showSummary()
{
System.out.println( "Available Courses:" );
Expand All @@ -84,15 +81,16 @@ public void showSummary()
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 );
System.out.println(student);
}
}
}

}

14 changes: 13 additions & 1 deletion 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 @@ -26,7 +27,18 @@ public Student findStudent( String studentId )

public void showSummary()
{
//TODO implement
System.out.println( "Total Students:" );
//loop through the students hashmap using mapName.keySet()
//for each key in the student...
for ( String key : students.keySet() ) {
// save each key (element) in the hashMap into a student obj
Student student = students.get( key );
String temp = student.getTemp().toString();
//print out each student until there's no more keys
//temp is the courses each student is enrolled into
System.out.println( student + temp);

}
}

public void enrollToCourse( String studentId, Course course )
Expand Down
84 changes: 54 additions & 30 deletions src/com/generation/utils/PrinterHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,68 @@
import java.util.Date;
import java.util.Scanner;

public class PrinterHelper
{
public class PrinterHelper {

public static void showMainMenu(){
System.out.println( "|-------------------------------|" );
System.out.println( "| Welcome to StudentGen |" );
System.out.println( "|-------------------------------|" );
System.out.println( "| Select 1 option: |" );
System.out.println( "| . 1 Register Student |" );
System.out.println( "| . 2 Find Student |" );
System.out.println( "| . 3 Enroll Student to Course |" );
System.out.println( "| . 4 Show Students Summary |" );
System.out.println( "| . 5 Show Courses Summary |" );
System.out.println( "| . 6 Exit |" );
System.out.println( "|-------------------------------|" );
public static void showMainMenu() {
System.out.println("|-------------------------------|");
System.out.println("| Welcome to StudentGen |");
System.out.println("|-------------------------------|");
System.out.println("| Select 1 option: |");
System.out.println("| . 1 Register Student |");
System.out.println("| . 2 Find Student |");
System.out.println("| . 3 Enroll Student to Course |");
System.out.println("| . 4 Show Students Summary |");
System.out.println("| . 5 Show Courses Summary |");
System.out.println("| . 6 Exit |");
System.out.println("|-------------------------------|");
}

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: |" );
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: |");
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");
//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! " );
System.out.println("| Enter student birth date(mm/dd/yyyy)|");
// set date format to mm/dd/yyyy
DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
// declare next input as dob
String dob = scanner.next();
// declare isValidDate to the return the value of isValidFormat method(if the date format is correct)
boolean isValidDate = isValidFormat(dob);
// while the format is not true, loop until the user input the correct format
while (!isValidDate){
System.out.println("| Enter student birth date(mm/dd/yyyy)|");
// retaking the user for DOB again
dob = scanner.next();
// resetting value on isValidDate and stops when true.
isValidDate = isValidFormat(dob);
}
// declare birthDate as the user's input into a DateFormat
Date birthDate = formatter.parse(dob);
System.out.println("|-------------------------------------|");
Student student = new Student(id, name, email, birthDate);
System.out.println("Student Successfully Registered! ");
System.out.println(student);
return student;
}

public static boolean isValidFormat(String dob) {
try {
// set the expected date format
DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
// check if date is matches the format
formatter.parse(dob);
return true;
} catch (Exception e) {
// throw error message if format is not matched
System.out.println("Wrong Date Format, Error: " +e.getMessage());
return false;
}
}
}
35 changes: 35 additions & 0 deletions test/com/generation/service/CourseServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.generation.service;

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

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

class CourseServiceTest {
//import CourseService object
public CourseService courseService;
//implement this constructor before each test
@BeforeEach
void setUp(){
courseService = new CourseService();
}
@Test
void getCourse() {
//assigning a var to getCourse's answer and converting it as a string
String code = String.valueOf(courseService.getCourse("INTRO-WEB-1"));
//assigning the answer string as a var
String answer = "Course{code='INTRO-WEB-1', name='Introduction to Web Applications', credits=9, module=Module{name='Web Development Fundamentals'}}";
assertEquals(answer,code);
}
@Test
void getCourseNull() {
//assigning a var to getCourse's answer and converting it as a string
String code = String.valueOf(courseService.getCourse("INTRO-W3B-2"));
//assigning the expected answer string as a var
String answer = "null";
//null is in a string because we made the valueOf null into a string within code assignment
assertEquals(answer,code);
}

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

import com.generation.model.Student;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class StudentServiceTest {
//import student and studentService object
public Student student;
public StudentService studentService;

//execute before each test
@BeforeEach
void setUp(){
studentService = new StudentService();
//initialize students
Student mitch = new Student("1", "mitch", "email", null);
Student vector = new Student("2","vector", "email2", null);
}
@Test
void findStudent() {
Student temp = studentService.findStudent("2");
assertEquals(null, temp );

}

}