Repository navigation
Expand file tree
/
Copy pathEmployee.java
More file actions
83 lines (66 loc) · 2.05 KB
/
Copy pathEmployee.java
File metadata and controls
83 lines (66 loc) · 2.05 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
import java.util.*;
public class Employee {
public static void main(String[] args) {
Employee employee1 = new Employee("BURCU", 1500000, 2);
promote(employee1);
promote(employee1);
promote(employee1);
demote(employee1);
employee1.doWork();
System.out.println(employee1.toString());
}
private static Employee[] employees = new Employee[8];
private static int count = 0;
private int id = -1;
private String name = "Default Employee";
private double salary = 23217.53;
private int level = 0;
public Employee(String name, double salary, int level) {
if (count > 8) {
throw new RuntimeException(" Cannot create more than 8 employees.");
}
this.name = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
this.salary = salary;
this.level = level;
this.id = generateId(level);
employees[count++] = this;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public int getLevel() {
return level;
}
public void setName(String name) {
this.name = name;
}
public void setSalary(Double salary) {
this.salary = salary;
}
public static void promote(Employee e) {
e.level++;
}
public static void demote(Employee e) {
e.level--;
}
private static int generateId(int level) {
int seconddigit = (int) (Math.random() * 10);
int thirddigit = (int) (Math.random() * 10);
int fourthdigit = (int) (Math.random() * 10);
String Id2 = "" + level + seconddigit + thirddigit + fourthdigit;
int ıd3 = Integer.parseInt(Id2);
return ıd3;
}
public void doWork() {
System.out.println(this.name + " DONE WORK");
}
public String toString() {
return " Name: " + getName() + " id " + getId() + " Salary: " + getSalary() + " Level " + getLevel();
}
}