-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
56 lines (46 loc) · 1.35 KB
/
Example.java
File metadata and controls
56 lines (46 loc) · 1.35 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
import java.util.ArrayList;
// This class, an extension of ArrayList, holds an individual example.
// The new method PrintFeatures() can be used to
// display the contents of the example.
// The items in the ArrayList are the feature values.
public class Example extends ArrayList<String>
{
// The name of this example.
private String name;
// The output label of this example.
private String label;
// The data set in which this is one example.
private ListOfExamples parent;
// Constructor which stores the dataset which the example belongs to.
public Example(ListOfExamples parent) {
this.parent = parent;
}
// Print out this example in human-readable form.
public void PrintFeatures()
{
System.out.print("Example " + name + ", label = " + label + "\n");
for (int i = 0; i < parent.getNumberOfFeatures(); i++)
{
System.out.print(" " + parent.getFeatureName(i)
+ " = " + this.get(i) + "\n");
}
}
// Adds a feature value to the example.
public void addFeatureValue(String value) {
this.add(value);
}
// Accessor methods.
public String getName() {
return name;
}
public String getLabel() {
return label;
}
// Mutator methods.
public void setName(String name) {
this.name = name;
}
public void setLabel(String label) {
this.label = label;
}
}