-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSVFile.java
55 lines (45 loc) · 1.29 KB
/
CSVFile.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
import java.io.FileWriter;
import java.util.ArrayList;
public class CSVFile {
ArrayList<CSVRow> rows;
public CSVFile() {
rows = new ArrayList<CSVRow>();
}
public CSVFile(ArrayList<CSVRow> rows) {
this.rows = rows;
}
public void saveFile(String fileName) throws Exception {
try(FileWriter myWriter = new FileWriter(fileName)) {
myWriter.write(toString());
} catch (Exception e) {
System.out.println("An error occurred while saving your file");
}
}
public Float getAverageCompletionTime() {
Float total = 0f;
int count = 0;
for (CSVRow row : rows) {
if (row.Complete != 0) {
total += row.Complete;
count++;
}
}
return count == 0 ? 0 : total/count;
}
@Override
public String toString() {
String toReturn = "";
toReturn += "Proc Time,PID,Start Burst,End Burst, Complete\n";
for (CSVRow row : rows) {
toReturn += row.toString() + "\n";
}
toReturn += "Average,,,," + getAverageCompletionTime();
return toReturn;
}
public CSVRow first() {
return rows.get(0);
}
public CSVRow last() {
return rows.get(rows.size() - 1);
}
}