-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
77 lines (69 loc) · 2.94 KB
/
Main.java
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
package com.generation;
import com.generation.model.Course;
import com.generation.model.Student;
import com.generation.service.StudentService;
import com.generation.service.CourseService;
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;
do {
PrinterHelper.showMainMenu();
option = scanner.nextInt();
switch (option) {
case 1 -> registerStudent(studentService, scanner);
case 2 -> findStudent(studentService, scanner);
case 3 -> enrollStudentToCourse(studentService, courseService, scanner);
case 4 -> showStudentsSummary(studentService);
case 5 -> showCoursesSummary(courseService);
}
} 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) {
courseService.showSummary();
}
private static void showStudentsSummary(StudentService studentService) {
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);
}
}