70 lines
1.6 KiB
Java
70 lines
1.6 KiB
Java
package net.woodyfolsom.cs6601.p2;
|
|
|
|
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;
|
|
|
|
@XStreamAlias("survey")
|
|
public class Survey {
|
|
private Map<Integer,String> dishes = new HashMap<Integer,String>();
|
|
private Map<Integer,String> categories = new HashMap<Integer,String>();
|
|
|
|
@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);
|
|
}
|
|
|
|
public int getDinerCount() {
|
|
return diners.size();
|
|
}
|
|
|
|
public String getDish(int dishId) {
|
|
return dishes.get(dishId);
|
|
}
|
|
|
|
public int getDishCount() {
|
|
return dishes.size();
|
|
}
|
|
|
|
public String getCategory(int catId) {
|
|
return categories.get(catId);
|
|
}
|
|
|
|
public int getCategoryCount() {
|
|
return categories.size();
|
|
}
|
|
}
|