-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathMain.java
More file actions
106 lines (97 loc) · 3.43 KB
/
Main.java
File metadata and controls
106 lines (97 loc) · 3.43 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
100
101
102
103
104
105
106
package com.generation;
import com.generation.model.Course;
import com.generation.model.Student;
import com.generation.service.CourseService;
import com.generation.service.StudentService;
import com.generation.utils.PrinterHelper;
import java.text.ParseException;
import java.util.Scanner;
public class Main
{
public static void main( String[] args )
throws ParseException
{
StudentService studentService = new StudentService();
CourseService courseService = new CourseService();
Scanner scanner = new Scanner( System.in );
int option = 0;
do
{
PrinterHelper.showMainMenu();
option = scanner.nextInt();
switch ( option )
{
case 1:
registerStudent( studentService, scanner );
break;
case 2:
findStudent( studentService, scanner );
break;
case 3:
enrollStudentToCourse( studentService, courseService, scanner );
break;
case 4:
showStudentsSummary( studentService, scanner );
break;
case 5:
showCoursesSummary( courseService, scanner );
break;
}
}
while ( option != 6 );
}
private static void enrollStudentToCourse( StudentService studentService, CourseService courseService,
Scanner scanner )
{
System.out.println( "Insert student ID" );
String studentId = scanner.next();
Student student = studentService.findStudent( studentId );
if ( student == null )
{
System.out.println( "Invalid Student ID" );
return;
}
System.out.println( student );
System.out.println( "Insert course ID" );
String courseId = scanner.next();
Course course = courseService.getCourse( courseId );
if ( course == null )
{
System.out.println( "Invalid Course ID" );
return;
}
System.out.println( course );
courseService.enrollStudent( courseId, student );
studentService.enrollToCourse( studentId, course );
System.out.println( "Student with ID: " + studentId + " enrolled successfully to " + courseId );
}
private static void showCoursesSummary( CourseService courseService, Scanner scanner )
{
courseService.showSummary();
}
private static void showStudentsSummary( StudentService studentService, Scanner scanner )
{
studentService.showSummary();
}
private static void findStudent( StudentService studentService, Scanner scanner )
{
System.out.println( "Enter student ID: " );
String studentId = scanner.next();
Student student = studentService.findStudent( studentId );
if ( student != null )
{
System.out.println( "Student Found: " );
System.out.println( student );
}
else
{
System.out.println( "Student with Id = " + studentId + " not found" );
}
}
private static void registerStudent( StudentService studentService, Scanner scanner )
throws ParseException
{
Student student = PrinterHelper.createStudentMenu( scanner );
studentService.subscribeStudent( student );
}
}