-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNameSurferEntry.java
86 lines (72 loc) · 2.5 KB
/
NameSurferEntry.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
78
79
80
81
82
83
84
85
/*
* File: NameSurferEntry.java
* --------------------------
* This class represents a single entry in the database. Each
* NameSurferEntry contains a name and a list giving the popularity
* of that name for each decade stretching back to 1900.
*/
import acm.program.*;
import acm.util.*;
import java.io.*;
import java.util.*;
public class NameSurferEntry extends ConsoleProgram implements NameSurferConstants {
/* Constructor: NameSurferEntry(line) */
/**
* Creates a new NameSurferEntry from a data line as it appears
* in the data file. Each line begins with the name, which is
* followed by integers giving the rank of that name for each
* decade.
*/
public NameSurferEntry(String line) {
// Reads the line from the speficied file and stores it in "line"
try {
BufferedReader rd = new BufferedReader(new FileReader(DATA_FILE));
while (true) {
line = rd.readLine();
if (line == null) break;
println(line);
}
rd.close();
} catch (IOException ex) {
throw new ErrorException(ex);
}
// Segments the the string in two parts, the name and the ranking data, using the
// StringTokenizer Class
// Stores the key and value for each name in a HashMap
names = new HashMap<String, Arrays>();
}
/* Method: getName() */
/**
* Returns the name associated with this entry.
*/
public String getName() {
// You need to turn this stub into a real implementation //
return null;
}
/* Method: getRank(decade) */
/**
* Returns the rank associated with an entry for a particular
* decade. The decade value is an integer indicating how many
* decades have passed since the first year in the database,
* which is given by the constant START_DECADE. If a name does
* not appear in a decade, the rank value is 0.
*/
public int getRank(int decade) {
// You need to turn this stub into a real implementation //
return 0;
}
/* Method: toString() */
/**
* Returns a string that makes it easy to see the value of a
* NameSurferEntry.
*/
public String toString() {
// You need to turn this stub into a real implementation //
return "";
}
/* 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 record;
private HashMap<String, Arrays> names;
}