-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployDetail.java
More file actions
196 lines (166 loc) · 7.18 KB
/
Copy pathEmployDetail.java
File metadata and controls
196 lines (166 loc) · 7.18 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import java.io.IOException;
import java.util.Scanner;
class EmployDetail extends Person {
private String name;
private String email;
private String position;
private String address;
private String employ_id;
private double employ_salary;
private int employ_contact;
private String emergencyContact_name;
private String emergencyContact_contact;
private String emergencyContact_address;
private String emergencyContact_email;
public EmployDetail(String name, String contactNo, String email, String address, String emergencyContact_address, String emergencyContact_contact, String emergencyContact_email, String emergencyContact_name) {
super(name, contactNo, email, address);
this.emergencyContact_address = emergencyContact_address;
this.emergencyContact_contact = emergencyContact_contact;
this.emergencyContact_email = emergencyContact_email;
this.emergencyContact_name = emergencyContact_name;
}
public EmployDetail() {
super();
}
@Override
public String toString() {
return "EmployDetail{" +
"address='" + address + '\'' +
", name='" + name + '\'' +
", email='" + email + '\'' +
", position='" + position + '\'' +
", employ_id='" + employ_id + '\'' +
", employ_salary=" + employ_salary +
", employ_contact=" + employ_contact +
", emergencyContact_name='" + emergencyContact_name + '\'' +
", emergencyContact_contact='" + emergencyContact_contact + '\'' +
", emergencyContact_address='" + emergencyContact_address + '\'' +
", emergencyContact_email='" + emergencyContact_email + '\'' +
"} " + super.toString();
}
public double getSalary() {
return employ_salary;
}
public String getEmail() {
return email;
}
public int getEmploy_contact() {
return employ_contact;
}
public String getEmploy_id() {
return employ_id;
}
public String getName() {
return name;
}
public String getPosition() {
return position;
}
public double getEmploy_salary() {
return employ_salary;
}
public void setEmploy_salary(double employ_salary) {
this.employ_salary = employ_salary;
}
public String getEmergencyContact_name() {
return emergencyContact_name;
}
public String getEmergencyContact_contact() {
return emergencyContact_contact;
}
public String getEmergencyContact_address() {
return emergencyContact_address;
}
public String getEmergencyContact_email() {
return emergencyContact_email;
}
@Override
public void getInfo() throws IOException {
Scanner sc = new Scanner(System.in);
// Get Employee Name
System.out.print("Enter Employee's Name --------: ");
name = sc.nextLine().trim();
while (name.isEmpty()) {
System.out.print("Name cannot be empty. Enter Employee's Name --------: ");
name = sc.nextLine().trim();
}
// Get Employee ID
System.out.print("Enter " + name + "'s ID ----------: ");
employ_id = sc.nextLine().trim();
while (employ_id.isEmpty()) {
System.out.print("ID cannot be empty. Enter " + name + "'s ID ----------: ");
employ_id = sc.nextLine().trim();
}
// Get Email
System.out.print("Enter " + name + "'s Email ID ----: ");
email = sc.nextLine().trim();
while (email.isEmpty() || !email.matches("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$")) {
System.out.print("Invalid email format. Enter " + name + "'s Email ID ----: ");
email = sc.nextLine().trim();
}
// Get Position
System.out.print("Enter " + name + "'s Position ----: ");
position = sc.nextLine().trim();
while (position.isEmpty()) {
System.out.print("Position cannot be empty. Enter " + name + "'s Position ----: ");
position = sc.nextLine().trim();
}
// Get Contact Info
System.out.print("Enter " + name + "'s Contact Info : ");
while (true) {
try {
employ_contact = Integer.parseInt(sc.nextLine().trim());
if (String.valueOf(employ_contact).length() != 9) {
throw new IllegalArgumentException("Contact number format is 712345678.");
}
break;
} catch (Exception e) {
System.out.print("Invalid contact number. Enter a valid Contact Info, Format is 712345678 : ");
}
}
// Get Salary
System.out.print("Enter " + name + "'s Salary ------: ");
while (true) {
try {
setEmploy_salary(Double.parseDouble(sc.nextLine().trim()));
if (getEmploy_salary() <= 0) {
throw new IllegalArgumentException("Salary must be greater than zero.");
}
break;
} catch (Exception e) {
System.out.print("Invalid salary. Enter a valid Salary ------: ");
}
}
// Get Emergency Contact Name
System.out.print("Enter " + name + "'s Emergency Contact's Name -: ");
emergencyContact_name = sc.nextLine().trim();
while (emergencyContact_name.isEmpty()) {
System.out.print("Emergency Contact's name cannot be empty. Enter " + name + "'s Emergency Contact's Name -: ");
emergencyContact_name = sc.nextLine().trim();
}
// Get Emergency Contact Number
System.out.print("Enter " + name + "'s Emergency Contact Number -: ");
emergencyContact_contact = sc.nextLine().trim();
while (emergencyContact_contact.isEmpty() || !emergencyContact_contact.matches("\\d{9}")) {
System.out.print("Emergency Contact number must be 9 digits. Enter " + name + "'s Emergency Contact Number -: ");
emergencyContact_contact = sc.nextLine().trim();
}
// Get Emergency Contact Address
System.out.print("Enter " + name + "'s Emergency Contact Address -: ");
emergencyContact_address = sc.nextLine().trim();
while (emergencyContact_address.isEmpty()) {
System.out.print("Emergency Contact address cannot be empty. Enter " + name + "'s Emergency Contact Address -: ");
emergencyContact_address = sc.nextLine().trim();
}
// Get Emergency Contact Email
System.out.print("Enter " + name + "'s Emergency Contact Email -: ");
emergencyContact_email = sc.nextLine().trim();
while (emergencyContact_email.isEmpty() || !emergencyContact_email.matches("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$")) {
System.out.print("Invalid email format. Enter " + name + "'s Emergency Contact Email -: ");
emergencyContact_email = sc.nextLine().trim();
}
// Generate Salary Summary
SalaryCalculator salaryCalculator = new SalaryCalculator();
SalaryCalculator.generateSalarySummary(employ_id, salaryCalculator, this.employ_salary);
}
}