-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewemployee.java
More file actions
68 lines (51 loc) · 2.34 KB
/
Copy pathnewemployee.java
File metadata and controls
68 lines (51 loc) · 2.34 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
import java.util.Scanner;
import java.io.*;
import java.text.ParseException;
import java.util.Date;
import java.text.SimpleDateFormat;
public class newEmployee {
//NOTE: why pass int empnum??? if the employee haven't been created how would there be an employee number
//newemployee.newEmployeeEvent(employeenumber)
public static void newEmployeeEvent() {
//get user input
Scanner scn = new Scanner(System.in);
System.out.println("Enter New Employee info: ");
System.out.println("Enter Member ID: ");
int empNum = scn.nextInt();
Scanner scn1 = new Scanner(System.in);
System.out.println("Enter Employee Full Name: ");
String name = scn1.nextLine();
Scanner scn2 = new Scanner(System.in);
System.out.println("Enter Address: ");
String address = scn2.nextLine();
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
dateFormat.setLenient(false);
Date dob = new Date(0);
boolean valid = false;
Scanner scn3 = new Scanner(System.in);
while(valid != true) {
try {
System.out.print("Enter Member Date of Birth(mm/dd/yyyy): ");
String input = scn3.nextLine();
dob = dateFormat.parse(input);
valid = true;
} catch (ParseException e) {
System.out.println("Invalid date format. Please enter date of birth in mm/dd/yyyy format.");
continue;
}
}
System.out.print("Enter Email: ");
String email = scn.nextLine().toLowerCase();
System.out.print("Enter Member SSN: ");
String socialsecuritynumber = scn.nextLine();
System.out.print("Enter Employee type (Librarian/Technician)");
String emptype = scn.nextLine().toLowerCase();
System.out.print("Creating a new employee.....");
//make new employee, make and get new employee id
Employee mem = new Employee(empNum, name, address, dob, email, socialsecuritynumber, emptype);
String stringMem = mem.toString();
//use savetofile to save to txt
SaveToFile.save(stringMem, "employees.txt");
System.out.println("New Employee Successfully Saved to file.");
}
}