-
Notifications
You must be signed in to change notification settings - Fork 1
/
reportGenerator.java
77 lines (65 loc) · 2.76 KB
/
reportGenerator.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
import java.io.*;
import java.util.*;
public class reportGenerator {
private File report;
private BufferedWriter writer;
private String name;
private ArrayList <PERT_Node> activities;
private ArrayList <pathAndDuration> paths;
public reportGenerator(String reportName, ArrayList reportActivities, ArrayList reportPaths) {
name = reportName;
activities = reportActivities;
paths = reportPaths;
try {
report = new File(name + ".txt");
writer = new BufferedWriter(new FileWriter(report));
} catch (IOException e) {
System.out.println(e);
}
}
public void createReport() {
sortActivities(activities);
try{
writer.write("\nReport name: " + name + "\n");
writer.write("\nTime: " + java.time.LocalTime.now() + "\n");
writer.write("\nDate: " + java.time.LocalDate.now() + "\n");
writer.write("\n___________________________________________\n");
writer.write("\nActivities: \n");
//output activities, duration and dependencies
for (int i = 0; i < activities.size(); i++) {
writer.write(activities.get(i).getName() +" : "+ activities.get(i).getDuration()+ "\n");
writer.write("\t[");
//loop through dependencies and write
for (int j = 0; j < activities.get(i).dependencies.length; j++) {
writer.write(activities.get(i).dependencies[j]);
if (j != activities.get(i).dependencies.length - 1) {
writer.write(", ");
}
}
writer.write("]");
writer.write("\n\n");
}
//output paths and durations
writer.write("\n___________________________________________\n");
writer.write("\nPaths: \n");
for (int i = 0; i < paths.size(); i++) {
writer.write(paths.get(i).getPath() + " : " + paths.get(i).getDuration() + "\n\n");
}
writer.close();
}catch (IOException e){
System.out.println(e);
}
}
public void sortActivities(ArrayList <PERT_Node> list) {
for (int i = 0; i < list.size(); i++) {
int key = (int)list.get(i).getName().charAt(0);
PERT_Node keyNode = new PERT_Node(list.get(i).getName(),list.get(i).dependencies, list.get(i).getDuration());
int j = i - 1;
while (j >= 0 && (int)list.get(j).getName().charAt(0) > key) {
list.set(j + 1, list.get(j));
j--;
}
list.set(j + 1, keyNode);
}
}
}