2015-09-07 11:44:36 -06:00
|
|
|
// enums/menu/Meal2.java
|
2015-06-15 17:47:35 -07:00
|
|
|
package enums.menu;
|
|
|
|
import com.mindviewinc.util.*;
|
|
|
|
|
|
|
|
public enum Meal2 {
|
|
|
|
APPETIZER(Food.Appetizer.class),
|
|
|
|
MAINCOURSE(Food.MainCourse.class),
|
|
|
|
DESSERT(Food.Dessert.class),
|
|
|
|
COFFEE(Food.Coffee.class);
|
|
|
|
private Food[] values;
|
|
|
|
private Meal2(Class<? extends Food> kind) {
|
|
|
|
values = kind.getEnumConstants();
|
|
|
|
}
|
|
|
|
public interface Food {
|
|
|
|
enum Appetizer implements Food {
|
|
|
|
SALAD, SOUP, SPRING_ROLLS;
|
|
|
|
}
|
|
|
|
enum MainCourse implements Food {
|
|
|
|
LASAGNE, BURRITO, PAD_THAI,
|
|
|
|
LENTILS, HUMMOUS, VINDALOO;
|
|
|
|
}
|
|
|
|
enum Dessert implements Food {
|
|
|
|
TIRAMISU, GELATO, BLACK_FOREST_CAKE,
|
|
|
|
FRUIT, CREME_CARAMEL;
|
|
|
|
}
|
|
|
|
enum Coffee implements Food {
|
|
|
|
BLACK_COFFEE, DECAF_COFFEE, ESPRESSO,
|
|
|
|
LATTE, CAPPUCCINO, TEA, HERB_TEA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public Food randomSelection() {
|
|
|
|
return Enums.random(values);
|
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
|
|
for(int i = 0; i < 5; i++) {
|
|
|
|
for(Meal2 meal : Meal2.values()) {
|
|
|
|
Food food = meal.randomSelection();
|
|
|
|
System.out.println(food);
|
|
|
|
}
|
|
|
|
System.out.println("---");
|
|
|
|
}
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|
|
|
|
/* Output:
|
2015-06-15 17:47:35 -07:00
|
|
|
SPRING_ROLLS
|
|
|
|
VINDALOO
|
|
|
|
FRUIT
|
|
|
|
DECAF_COFFEE
|
|
|
|
---
|
|
|
|
SOUP
|
|
|
|
VINDALOO
|
|
|
|
FRUIT
|
|
|
|
TEA
|
|
|
|
---
|
|
|
|
SALAD
|
|
|
|
BURRITO
|
|
|
|
FRUIT
|
|
|
|
TEA
|
|
|
|
---
|
|
|
|
SALAD
|
|
|
|
BURRITO
|
|
|
|
CREME_CARAMEL
|
|
|
|
LATTE
|
|
|
|
---
|
|
|
|
SOUP
|
|
|
|
BURRITO
|
|
|
|
TIRAMISU
|
|
|
|
ESPRESSO
|
|
|
|
---
|
2015-09-07 11:44:36 -06:00
|
|
|
*/
|