-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEmployeeDemo.java
53 lines (40 loc) · 1.47 KB
/
EmployeeDemo.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
import java.util.Random;
public class EmployeeDemo {
private enum EmployeeType {
WORKER,
MANAGER
}
public static void main(String[] args) {
Employee[] employees = new Employee[5];
for(int i = 0; i < 5; i++) {
EmployeeType et = getEmployeeType();
Employee currentEmployee;
if(et == EmployeeType.WORKER) {
currentEmployee = new Worker("Will", "Jones", 20);
}
else {
currentEmployee = new Manager("Sam", "Jones", 38);
}
employees[i] = currentEmployee;
}//end for creating employees
for(Employee employee : employees) {
System.out.println("Name: " + employee.getFirstName() +
" " + employee.getLastName() + ", age " +
employee.getAge() + " says , " );
System.out.println("\t" + employee.work() + "\n");
}//end for
}//end main
public static EmployeeType getEmployeeType() {
EmployeeType result;
Random rand = new Random();
final int UPPER_BOUND = 2;
int whichOne = rand.nextInt(UPPER_BOUND);
if(whichOne == 0) {
result = EmployeeType.WORKER;
}
else {
result = EmployeeType.MANAGER;
}
return result;
}
}