-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEmployee.java
More file actions
107 lines (97 loc) · 3.16 KB
/
Employee.java
File metadata and controls
107 lines (97 loc) · 3.16 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment.pkg1;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Employee {
private String Name;
private String Password;
private String Filename;
public Employee() {
Filename = "RegisteredUsers.txt";
}
public boolean isRegistered(String newName, String newPassword) {
boolean isRegistered;
Name = newName;
Password = newPassword;
FileWriter writer;
try {
writer = new FileWriter(Filename, true);
writer.write(Name + System.getProperty("line.separator"));
writer.write(Password + System.getProperty("line.separator"));
writer.write("##" + System.getProperty("line.separator"));
isRegistered = true;
writer.flush();
writer.close();
writer = null;
} catch (IOException ioe) {
isRegistered = false;
}
return isRegistered;
}
public boolean isUser(String newName, String newPassword) {
Name = newName;
Password = newPassword;
boolean isNameFound = false;
boolean isPasswordFound = false;
boolean isFound = false;
int NameLocator = 0;
int i = 0;
String record;
FileReader reader;
try {
reader = new FileReader(Filename);
BufferedReader bin = new BufferedReader(reader);
record = new String();
while ((record = bin.readLine()) != null) {
i++;
if (Name.contentEquals(record)) {
isNameFound = true;
NameLocator = i;
}
if (i == NameLocator + 1) {
if (Password.contentEquals(record)) {
isPasswordFound = true;
}
}
}
bin.close();
bin = null;
if (isNameFound == true && isPasswordFound == true) {
isFound = true;
}
} catch (IOException ioe) {
isFound = false;
}
return isFound;
}
public boolean isEmployee(String newName) {
Name = newName;
boolean isEmployeeFound = false;
if (Name.substring(Name.lastIndexOf(":") + 1).matches("Employee")) {
isEmployeeFound = true;
}
return isEmployeeFound;
}
public boolean isAdministrator(String newName) {
Name = newName;
boolean isAdministratorFound = false;
if (Name.substring(Name.lastIndexOf(":") + 1).matches("Administrator")) {
isAdministratorFound = true;
}
return isAdministratorFound;
}
public boolean isCustomer(String newName) {
Name = newName;
boolean isCustomerFound = false;
if (Name.substring(Name.lastIndexOf(":") + 1).matches("Customer")) {
isCustomerFound = true;
}
return isCustomerFound;
}
}