-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmployeeList.java
114 lines (108 loc) · 3.35 KB
/
EmployeeList.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
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
package project;
import java.util.ArrayList;
import java.util.Scanner;
public class EmployeeList {
ArrayList<Employees> list = new ArrayList<>();
public void input() {
do {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter ID: ");
String ID = scanner.nextLine();
if (ID.equals("") || ID == null){
break;
}
System.out.print("Enter name: ");
String name = scanner.nextLine();
System.out.print("Enter Salary: ");
double baseSalary = Double.parseDouble(scanner.nextLine());
System.out.print("Enter employeeType (fulltime/contract): ");
String employeeType = scanner.nextLine();
if (employeeType.equalsIgnoreCase("fulltime")) {
System.out.print("Enter percent: " );
double percent = scanner.nextDouble();
Employees NewEmployee = new FullTimeEmployee(ID, name, baseSalary, employeeType , percent);
list.add(NewEmployee);
}else if(employeeType.equalsIgnoreCase("contract")) {
System.out.print("Enter Bonus: ");
double Bonus = scanner.nextDouble();
Employees NewEmployee = new Contractor(ID, name, baseSalary, employeeType , Bonus);
list.add(NewEmployee);
}else {
System.out.println("Please re-enter your information!");
}
}while (true);
}
public void output () {
for (Employees nv: list) {
System.out.printf("ID: %s | Name: %s | EmployeeType: %s | newSalary: %.2f\n", nv.getID(), nv.getname(), nv.getemployeeType(), nv.getSalary());
}
}
public void find() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter employee's ID: ");
String ID = sc.nextLine();
Boolean check = false;
for (Employees n : list) {
if (ID.equalsIgnoreCase(n.getID()));{
System.out.printf("ID: %s| Name: %s| EmployeeType:%s| newSalary:%.2f\n", n.getID(), n.getname(), n.getemployeeType(),n.getSalary());
check =true;
break;
}
}
if (check == false) {
System.out.println("This employee is not exist !");
}
}
public void delete() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter ID to remove: ");
String ID = sc.nextLine();
Boolean check = false;
for (Employees n : list) {
if (ID.equalsIgnoreCase(n.getID())) {
list.remove(n);
check = true;
break;
}
}
if (check == false) {
System.out.println("This employee is not exist");
}else {
System.out.println("This ID is deleted !");
}
}
public void menu() {
Scanner s = new Scanner(System.in);
int select = 0 ;
do {
System.out.println("\n Menu");
System.out.println("1. Enter employees's information");
System.out.println("2. All Employees's information");
System.out.println("3. Find employee by ID");
System.out.println("4. Remove employee");
System.out.println("0. Quit");
System.out.println("Enter your selection:");
select = s.nextInt();
if (select !=0) {
switch (select) {
case 0:
break;
case 1:
input();
break;
case 2:
output();
break;
case 3:
find();
break;
case 4:
delete();
break;
default:
System.out.println("Wrong information, Please Enter Again !");
}
}
}while (select !=0);
}
}