-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrinterHelper.java
53 lines (48 loc) · 2.28 KB
/
PrinterHelper.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
package com.generation.utils;
import com.generation.model.Student;
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 static Student createStudentMenu(Scanner scanner) {
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: |");
String id = scanner.next();
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");
Date birthDate = null;
while (birthDate == null) {
try {
birthDate = formatter.parse(scanner.next());
} catch (ParseException e) {
System.out.println("Invalid date format. Please enter the date in the 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;
}
}