· 9 years ago · Nov 23, 2016, 04:34 PM
1package lol;
2public class Employee
3{
4 private String empName;
5 private static long idGen = 100;
6 private long uniqueId;
7 private int day, month, year;
8 private String password;
9 private String email;
10 private static String emailSuffix = "@theFarm.org";
11 private String phone;
12 private boolean authorised;
13 //final private String secretKey = "23131ggfgf";
14
15 public Employee()
16 {
17 empName = "";
18 password = "";
19 day = 0;
20 month = 0;
21 year = 0;
22 email = "";
23 phone = "";
24 uniqueId = idGen++;
25 authorised = false;
26 }
27
28 public Employee(String empName, int day, int month, int year, String password, String phone)
29 {
30 this.empName = empName.toLowerCase();
31 this.password = password;
32 this.day = day;
33 this.month = month;
34 this.year = year;
35 this.email = empName.replaceAll("\\s+","") + emailSuffix; // Removes whitespace from String name with "".
36 this.phone = phone;
37 uniqueId = idGen++;
38 authorised = false;
39 }
40
41 public void setLogInState()
42 {
43 authorised = true;
44 }
45
46 public Boolean getLogInState()
47 {
48 return authorised;
49 }
50
51 public long getIdGen()
52 {
53 return idGen;
54 }
55
56 public long getId()
57 {
58 return uniqueId;
59 }
60
61 public String getEmpName()
62 {
63 return empName;
64 }
65
66 public void setEmpName(String empName)
67 {
68 this.empName = empName;
69 }
70
71 public int getDay() {
72 return day;
73 }
74
75 public void setDay(int day) {
76 this.day = day;
77 }
78
79 public int getMonth() {
80 return month;
81 }
82
83 public void setMonth(int month) {
84 this.month = month;
85 }
86
87 public int getYear() {
88 return year;
89 }
90
91 public void setYear(int year) {
92 this.year = year;
93 }
94
95
96
97 public String concatDOB()
98 {
99 return day + "-" + month + "-" + year;
100 }
101
102 public String getPassword()
103 {
104 return password;
105 }
106
107 public void setPassword(String password)
108 {
109 this.password = password;
110 }
111
112 public String getEmail()
113 {
114 return email;
115 }
116
117 public void setEmail(String email)
118 {
119 this.email = email;
120 }
121
122 public String getPhone()
123 {
124 return phone;
125 }
126
127 public void setPhone(String phone)
128 {
129 this.phone = phone;
130 }
131
132
133
134 public boolean isAuthorised(long id, String password)
135 {
136 return getId() == id && this.password.equals(password);
137 }
138
139 public boolean isValid(String empName, int day, int month, int year, String password, String phone)
140 {
141 return this.empName.equalsIgnoreCase(empName) ||
142 this.day == 0 ||
143 this.month == 0 ||
144 this.year == 0 ||
145 this.phone.equals(phone);
146 }
147
148 @Override
149 public String toString()
150 {
151 return "\n\nEmployee Name: " + getEmpName() +"\nID: " + getId() + "\nDate of Birth: " + concatDOB() + "\nEmail: " + getEmail() + "\nPhone Number: " + getPhone();
152 }
153
154 public String toFile()
155 {
156 return getEmpName() + ";" + concatDOB() + ";" + this.password + ";" + getPhone();
157 }
158
159}