예제 #1
0
 public ArrayList<Category> getMenuCategories() {
   ArrayList<Category> categories = new ArrayList<Category>();
   for (Category c : Category.values()) {
     categories.add(c);
   }
   return categories;
 }
예제 #2
0
 private MenuItem createMenuItem(String currentLine) {
   String[] tokens = currentLine.split("\\s*,\\s*");
   String itemName = tokens[0].trim();
   double price = Double.parseDouble(tokens[1].trim());
   Category cat = Category.valueOf(tokens[2].trim());
   MenuItem item = new MenuItem(itemName, price, cat);
   return item;
 }
예제 #3
0
  public MenuController() {

    menuItemsByCategory = new HashMap<Category, ArrayList<MenuItem>>();
    for (Category category : Category.values()) {
      ArrayList<MenuItem> list = new ArrayList<MenuItem>();
      menuItemsByCategory.put(category, list);
    }

    loadMenuFromFile(MenuController.LUNCH_MENU_PATH);
  }
예제 #4
0
  public void loadMenuFromFile(String path) {

    for (Category category : Category.values()) {
      menuItemsByCategory.get(category).clear();
    }

    BufferedReader reader = null;
    try {
      reader = new BufferedReader(new FileReader(path));
      String currentLine;
      while ((currentLine = reader.readLine()) != null) {

        MenuItem item = createMenuItem(currentLine);
        ArrayList<MenuItem> list = menuItemsByCategory.get(item.getCategory());
        list.add(item);
      }

    } catch (IOException ex) {
      System.err.println(ex.getMessage());
    }
  }