-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vegetable.java
51 lines (43 loc) · 1.27 KB
/
Vegetable.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
package recommender.sol;
import recommender.src.IAttributeDatum;
import java.util.LinkedList;
/**
* class representing vegetable data
*/
public class Vegetable implements IAttributeDatum {
/**
* has a list of atrtibutes and a corresponding list of values taken at each attribute
*/
String[] attribute;
Object[] values;
/**
* Constructor
*
* @param values are entered as an Array
*/
public Vegetable(Object[] values) {
this.attribute = new String[]{"name", "color", "lowCarb", "highFiber", "likeToEat"}; // hard code this array
this.values = values;
}
@Override
public Object getValueOf(String attributeName) {
for (int i = 0; i < this.attribute.length; i++) {
if (this.attribute[i].equals(attributeName)) {
return this.values[i];
}
}
throw new RuntimeException("attribute not found");
}
/**
* gets the attributes of the vegetable class
*
* @return
*/
public LinkedList<String> getAttributes() {
LinkedList<String> list = new LinkedList<String>();
for (String att : this.attribute) {
list.addLast(att);
}
return list;
}
}