blob: ed1f42002fd92bc1b12fe812cf0b46eed35f72a8 (
plain)
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
|
import java.util.ArrayList;
import java.io.IOException;
import java.io.EOFException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.util.Scanner;
import java.io.PrintStream;
public class Lines {
private ArrayList<int[]> lines;
public Lines(String loadpath) throws IOException, LoadException {
this.lines = new ArrayList<int[]>();
FileReader f = null;
BufferedReader buff = null;
try {
f = new FileReader(loadpath);
buff = new BufferedReader(f);
String line;
while((line = buff.readLine()) != null) {
this.readRow(line);
}
} finally {
if (f != null) {
f.close();
}
}
}
void readRow(String line) throws LoadException {
// you are a pirate
int[] arr = new int[10];
int i;
Scanner sc = null;
try {
sc = new Scanner(line);
for (i = 0; i < 10; i++) {
if (!sc.hasNextInt()) {
break;
}
int n = sc.nextInt();
// OPG 3
if (n > 90) {
throw new LoadException(n, "is above 90");
}
// OPG 4
//a assert (n <= 90) : "is above 90";
arr[i] = n;
}
} finally {
sc.close();
}
if (i > 0) {
lines.add(arr);
}
}
public void print(PrintStream out) {
for (int[] arr : this.lines) {
for (int i : arr) {
out.printf("%-3d ", i);
}
out.print(System.lineSeparator());
}
}
}
|