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
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" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<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>
23 changes: 18 additions & 5 deletions src/com/generation/model/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Student( String id, String name, String email, Date birthDate )

public void enrollToCourse( Course course )
{
//TODO implement this method
courses.add(course);
}

public void registerApprovedCourse( Course course )
Expand All @@ -33,13 +33,26 @@ public void registerApprovedCourse( Course course )


public boolean isAttendingCourse( String courseCode )
{
//TODO implement this method
{ //TODO implement this method
//iterate Course object from arrayList of courses
//arrayList(courses) for each method

for(Course course:courses) {
//in the arrayList use getCode method
//to check if it matches with the user's input(courseCode) use .equals
if (course.getCode().equals(courseCode)) {
//if it equals return true
return true;
} else {
//if not equals return false
return false;
}
}
return false;

}

@Override
public double getAverage()
public double getAverage()
{
return average;
}
Expand Down
1 change: 1 addition & 0 deletions src/com/generation/service/CourseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public Course getCourse( String code )
{
if ( courses.containsKey( code ) )
{
// input course code
return courses.get( code );
}
return null;
Expand Down
33 changes: 33 additions & 0 deletions src/com/generation/service/CourseServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 static org.junit.jupiter.api.Assertions.*;

class CourseServiceTest {
// import object from CourseService
public CourseService courseService;
// before each test implement this constructor
@BeforeEach
void setUp() {
courseService = new CourseService(); }

@Test
void getCourseNull() {
Course course = courseService.getCourse("Invalid Code");
assertNull(course);
}

@Test
void registerCourse() {
Module moduleWebFundamentals = new Module("INTRO-WEB", "Web Development Fundamentals",
"Introduction to fundamentals of web development" );
Course course = new Course("INTRO-WEB-7", "Introduction to JavaScript for Web Development", 9, moduleWebFundamentals );
courseService.registerCourse(course);
Course course1 = courseService.getCourse("INTRO-WEB-7");
assertEquals(course, course1);
}
}
10 changes: 9 additions & 1 deletion src/com/generation/service/StudentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ public Student findStudent( String studentId )

public void showSummary()
{
//TODO implement
// implement students values to showSummary
System.out.println( "Students: ");
for (Student student : students.values())
{
System.out.println(student.toString());

}
}


// implement students id into enrollToCourse
public void enrollToCourse( String studentId, Course course )
{
if ( students.containsKey( studentId ) )
Expand Down
37 changes: 37 additions & 0 deletions src/com/generation/service/StudentServiceTest.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 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 object from StudentService
public StudentService studentService() {
return null;
}

// before each test implement
@BeforeEach
void setUp() {
StudentService StudentService = new StudentService();
}

@org.junit.jupiter.api.Test
void showStudentSummary() {
StudentService studentService = new StudentService();
studentService.showSummary();
}

@org.junit.jupiter.api.Test
void enrollToCourse() {
StudentService studentService = new StudentService();
Module module;
studentService.enrollToCourse("1", new Course( "INTRO-CS-2", "Introduction to Algorithms",
9, new Module("INTRO-CS", "Introduction to Computer Science",
"Introductory module for the generation technical programs")));
}
}
87 changes: 53 additions & 34 deletions src/com/generation/utils/PrinterHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,69 @@

import com.generation.model.Student;

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

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 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 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(student);
return student;
System.out.println("| Enter student birth date(mm/dd/yyyy)|");

// format set date as MM/dd/yyyy
DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
// input student's date of birth
boolean toValidDate = false;
Date birthDate = null;

/* TODO validate date format and catch exception to avoid crash */

// input try...catch and return exception
while(!toValidDate) {


try {
birthDate = formatter.parse(scanner.next());
toValidDate = true;
} catch (ParseException e) {
System.out.println("Invalid Date!");
System.out.println("| Enter valid date format (mm/dd/yyyy)|");
}
}
System.out.println("|-------------------------------------|");
Student student = new Student(id, name, email, birthDate);
System.out.println("Student Successfully Registered! ");
System.out.println(student);
return student;

}
}

}