-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathCourseService.java
More file actions
99 lines (86 loc) · 3.85 KB
/
CourseService.java
File metadata and controls
99 lines (86 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.generation.service;
import com.generation.model.Course;
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;
public class CourseService
{
private final Map<String, Course> courses = new HashMap<>();
private final Map<String, List<Student>> enrolledStudents = new HashMap<>();
public CourseService()
{
Module module = new Module( "INTRO-CS", "Introduction to Computer Science",
"Introductory module for the generation technical programs" );
registerCourse( new Course( "INTRO-CS-1", "Introduction to Computer Science", 9, module ) );
registerCourse( new Course( "INTRO-CS-2", "Introduction to Algorithms", 9, module ) );
registerCourse( new Course( "INTRO-CS-3", "Algorithm Design and Problem Solving - Introduction ", 9, module ) );
registerCourse( new Course( "INTRO-CS-4", "Algorithm Design and Problem Solving - Advanced", 9, module ) );
registerCourse( new Course( "INTRO-CS-5", "Terminal Fundamentals", 9, module ) );
registerCourse( new Course( "INTRO-CS-6", "Source Control Using Git and Github", 9, module ) );
registerCourse( new Course( "INTRO-CS-7", "Agile Software Development with SCRUM", 9, module ) );
Module moduleWebFundamentals = new Module( "INTRO-WEB", "Web Development Fundamentals",
"Introduction to fundamentals of web development" );
registerCourse( new Course( "INTRO-WEB-1", "Introduction to Web Applications", 9, moduleWebFundamentals ) );
registerCourse( new Course( "INTRO-WEB-2", "Introduction to HTML", 9, moduleWebFundamentals ) );
registerCourse( new Course( "INTRO-WEB-3", "Introduction to CSS", 9, moduleWebFundamentals ) );
registerCourse( new Course( "INTRO-WEB-4", "Advanced HTML", 9, moduleWebFundamentals ) );
registerCourse( new Course( "INTRO-WEB-5", "Advanced CSS", 9, moduleWebFundamentals ) );
registerCourse( new Course( "INTRO-WEB-6", "Introduction to Bootstrap Framework", 9, moduleWebFundamentals ) );
registerCourse(
new Course( "INTRO-WEB-7", "Introduction to JavaScript for Web Development", 9, moduleWebFundamentals ) );
}
public void registerCourse( Course course )
{
courses.put( course.getCode(), course );
}
public Course getCourse( String code )
{
if ( courses.containsKey( code ) )
{
// input course code
return courses.get( code );
}
return null;
}
public void enrollStudent( String courseId, Student student )
{
if ( !enrolledStudents.containsKey( courseId ) )
{
enrolledStudents.put( courseId, new ArrayList<>() );
}
enrolledStudents.get( courseId ).add( student );
}
public void showEnrolledStudents( String courseId )
{
if ( enrolledStudents.containsKey( courseId ) )
{
List<Student> students = enrolledStudents.get( courseId );
for ( Student student : students )
{
System.out.println( student );
}
}
}
public void showSummary()
{
System.out.println( "Available Courses:" );
for ( String key : courses.keySet() )
{
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 );
}
}
}
}