"Implement the MenuRandomize class. The constructor receives the file name of 4 files, one for each type of meal, and uses FileManager to load data from these text files into the 4 ArrayList decleared as properties (one array for each type of dish)." Right now I am stuck on the randomMenu(). How do I randomly select from arrayLists and add to an object? I think I should return Menu but it returns an error. I have selected a random number. Do I take that index from another arrayList (that element) and store it in a different arrayList ? I have this so far.
public class MenuRandomize {
private ArrayList<Entree> entree;
private ArrayList<Salad> salad;
private ArrayList<Dessert> dessert;
private ArrayList<Side> side;
public MenuRandomize(String entreeFile, String sideFile, String saladFile, String dessertFile) {
entree = FileManager.readEntrees(entreeFile);
dessert = FileManager.readDesserts(dessertFile);
side= FileManager.readSides(sideFile);
salad= FileManager.readSalads(saladFile);
}
public randomMenu() {
ArrayList<Menu> menu;
int indexEntrees=(int) Math.random() * entree.size() - 1;
entree = entrees.get(indexEntrees);
int indexD=(int) Math.random() * dessert.size() - 1;
dessert = desserts.get(indexD);
**<----add element here to arrayList <Menu>?**
int indexSalad=(int) Math.random() * salad.size() - 1;
salad = salads.get(indexSalad);
int indexSide=(int) Math.random() * side.size() - 1;
entree = sides.get(indexSide);
return null; **<--- return Menu?**
Aucun commentaire:
Enregistrer un commentaire