Work in progress.
This commit is contained in:
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamImplicit;
|
||||
@@ -16,6 +17,32 @@ public class Survey {
|
||||
@XStreamImplicit(itemFieldName="diner")
|
||||
private List<Diner> diners = new ArrayList<Diner>();
|
||||
|
||||
public double getAverageRating(int recipeIndex) {
|
||||
double total = 0.0;
|
||||
for (Diner diner : diners) {
|
||||
total += diner.getRating(recipeIndex);
|
||||
}
|
||||
return total/diners.size();
|
||||
}
|
||||
|
||||
public boolean isDiner(String category) {
|
||||
for (int i = 0; i < diners.size(); i++) {
|
||||
if (isCategory(i,category)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCategory(int dinerIndex, String category) {
|
||||
for (Entry<Integer,String> entry : categories.entrySet()) {
|
||||
if (entry.getValue().equals(category)) {
|
||||
return diners.get(dinerIndex).isCategory(entry.getKey());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Diner getDiner(int dinerIndex) {
|
||||
return diners.get(dinerIndex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user