-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathPrinterHelper.java
More file actions
61 lines (56 loc) · 2.62 KB
/
PrinterHelper.java
File metadata and controls
61 lines (56 loc) · 2.62 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
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 )
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: |");
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");
//TODO validate date format and catch exception to avoid crash
//need catch statement to handle the error -- prompt the user to re-enter the info
//can write some code to handle proper date range -- not required
//Is this where this goes???
boolean validDate = false;
Date birthDate = null;
while(!validDate){
try {
birthDate = formatter.parse(scanner.next());
validDate = true;
} catch (ParseException e) {
System.out.println("Please enter a valid date");
}
}
System.out.println("|-------------------------------------|");
Student student = new Student(id, name, email, birthDate);
System.out.println("Student Successfully Registered! ");
System.out.println(student);
return student;
}
}