Repository navigation
Expand file tree
/
Copy pathStatsReader.java
More file actions
60 lines (49 loc) · 1.43 KB
/
Copy pathStatsReader.java
File metadata and controls
60 lines (49 loc) · 1.43 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
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
/** Reads stats **/
public class StatsReader {
private final String fileName;
private int matches;
private int p1Goals;
private int p2Goals;
public StatsReader(String fileName) {
this.fileName = fileName;
}
// reads the matches played and average goals per player
public void readStats() throws IOException {
FileReader fr = null;
BufferedReader reader = null;
try {
fr = new FileReader(fileName);
reader = new BufferedReader(fr);
String line = reader.readLine();
while (line != null) {
String[] tokens = line.split(",");
matches = Integer.parseInt(tokens[0]);
p1Goals = Integer.parseInt(tokens[1]);
p2Goals = Integer.parseInt(tokens[2]);
line = reader.readLine();
}
} finally {
if (reader != null) {
reader.close();
}
if (fr != null) {
fr.close();
}
}
}
public int getMatches() {
return matches;
}
public int getP1Goals() {
return p1Goals;
}
public int getP2Goals() {
return p2Goals;
}
public int updateMatches() {
return matches + 1;
}
}