-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheOffice.java
189 lines (148 loc) · 4.91 KB
/
TheOffice.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//Cory Fink
//TA: Michael Arboleda
//Project 4
//Section: I dont know my section and I couldn't find it on canvas
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class TheOffice {
private Employee[] workers;
public void setWorkers(Employee[]workers){
this.workers = workers;
}
public Employee[] getWorkers(){
return workers;
}
//Constructor
TheOffice(){
}
TheOffice(String fileLoc) throws TaskLevelException{
//This is used to read a file, do NOT edit!!!
Scanner fs = null;
File f = null;
//Try Catch on file
try{
f = new File(fileLoc);
fs = new Scanner(f);
}
catch(FileNotFoundException e){
System.out.println("FileNotFoundException: The file \""+ fileLoc + "\" could not be found.");
}
//First Line is number of employees
int size = Integer.parseInt(fs.nextLine());
workers = new Employee[size];
//This might be useful, feel free to delete, or not use these
RegionalManager manager = null;
int supremum = 0;
AssistantRegionalManager assistantManager = null;
int ATRM = 0;
//Loops through file
for(int i = 0; i < size; i++){
//Sets temp variables for all possible member variables
int IDNumber = -1;
String name = null;
Task[] taskList = null;
int RegionNum = -1;
int minimumTask = -1;
int numClients = -1;
String[] products = null;
int maxTaskComplexityLevel = -1;
//Check which type of employee
String type = fs.nextLine().trim();
//Get Standard information (id, name)
IDNumber = Integer.parseInt(fs.nextLine().trim());
name = fs.nextLine();
//Gets number of tasks and makes a task array based on the size
int tasks = Integer.parseInt(fs.nextLine().trim());
taskList = new Task[tasks];
//Fills up Task List
for(int j = 0; j < tasks; j++){
//Gets information for task
String work = fs.nextLine();
int num = Integer.parseInt(fs.nextLine().trim());
//Sets task at array spot
taskList[j] = new Task(work, num);
}
//Scanner read for Regional Manager. Use this as an example to do the other 3 types
if(type.equals("RegionalManager")){
//Gets Region Number and Minimum Task Level
RegionNum = Integer.parseInt(fs.nextLine().trim());
minimumTask = Integer.parseInt(fs.nextLine().trim());
//Loop through the Task list
for(int j = 0; j < taskList.length; j++ ){
//If a task is below the minimum task level, throw exception
if(taskList[j].getLevel() < minimumTask){
throw new TaskLevelException(taskList[j].getLevel());
}
}
//set manager to new regional manager
manager = new RegionalManager(IDNumber, name, taskList, RegionNum, minimumTask);
//set workers[i] to regional manager
workers[i] = manager;
//Set supremum (Might be useful)
supremum = minimumTask;
}
else if(type.equals("AssistantRegionalManager")){
}
else if(type.equals("SalesAssociate")){
}
else if(type.equals("Receptionist")){
}
}
//Set up Employee Arrays for regional managerget
Employee[] a = new Employee[size -1];
for(int i = 0, j = 0; i < workers.length; i++){
if(!(workers[i] instanceof RegionalManager)){
a[j++] = workers[i];
}
}
//If there is a manager, set the subordinate array
if(manager != null){
manager.setSubordinates(a);
}
}
//toString method
//creates a final document string
public String toString(){
String emp="";
//accesses every employee
for(int i=0;i<workers.length;i++){
//checks if the worker is a Regional Manager, if so adds their toString
if(workers[i]instanceof RegionalManager){
emp+=((RegionalManager)workers[i]).toString();
}
}
return emp;
}
//levelDisplay method
// will make and return a string that has employees’ name and their minimum task leve
public String levelDisplay(){
int level =1;
String emp2 = "";
for(int i=0;i<workers.length;i++){
if(workers[i]instanceof RegionalManager){
level=((RegionalManager)workers[i]).getMinimumTask();
}
else if(workers[i]instanceof AssistantRegionalManager){
level=((AssistantRegionalManager)workers[i]).getMinimumTask();
}
else{
level=1;
}
emp2+="Name: "+workers[i].getName()+"\tLevel: "+level;
if(i!=workers.length-1)
emp2+= "\n";
}
return emp2;
}
public static void main(String[] args) throws TaskLevelException{
//Gets location for file
TheOffice o = new TheOffice((args[0]+".txt"));
//Prints office, then the current level display
System.out.println(o + "\n\n\n" + o.levelDisplay());
//Sorts(by name) the employee array
Sorter.sort(o.getWorkers());
//Prints the sorted(by name) level display
System.out.println("\n\n\n" + o.levelDisplay());
}
}