-
Notifications
You must be signed in to change notification settings - Fork 1
/
NameSurferTester.java
76 lines (58 loc) · 2.16 KB
/
NameSurferTester.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
/**
* Created by IntelliJ IDEA.
* User: nicolasechavarria
* Date: 3/19/12
* Time: 9:01 PM
* To change this template use File | Settings | File Templates.
*/
import acm.program.*;
import acm.util.*;
import java.io.*;
import java.util.*;
public class NameSurferTester extends ConsoleProgram {
public void run() {
getLine();
}
private void getLine() {
try {
BufferedReader rd = new BufferedReader(new FileReader(DATA_FILE));
while (true) {
line = rd.readLine();
if (line == null) break;
println(line);
// Segments the the string in two parts, the name and the ranking data, using the
// StringTokenizer Class
println("In tokenizer");
String result = "";
StringTokenizer tokenizer = new StringTokenizer(line, " ");
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (Character.isLetter(token.charAt(1))){
name = token;
println(name);
} else {
//TODO Change strings to integers
String[] ranking = new String[10];
for (int i = 0; i < 10; i++) {
println(token);
ranking[i] = token;
}
println(ranking);
}
}
println(result);
// Stores the key (string) and value (array) for each name in a HashMap
//names = new HashMap<String, Arrays>();
}
rd.close();
} catch (IOException ex) {
throw new ErrorException(ex);
}
}
/* Private constants */
private static final String DATA_FILE = "/Users/nicolasechavarria/Documents/Personal/Stanford University/SEE/CS106A/Assignments/CS106A_06/names-data-one-line.txt";
/* Private instance variables */
private String line;
private HashMap<String, Arrays> names;
private String name;
}