Advertisement
adityak2207

RecipeList.java

Jan 28th, 2025
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class RecipeList {
  4.     private ArrayList<Recipe> recipes;
  5.  
  6.     public RecipeList() {
  7.         this.recipes = new ArrayList<>();
  8.     }
  9.  
  10.     public void add(Recipe recipe) {
  11.         this.recipes.add(recipe);
  12.     }
  13.  
  14.     public void list() {
  15.         System.out.println("Recipes: ");
  16.         for (int i=0; i<this.recipes.size(); i++) {
  17.             System.out.println(this.recipes.get(i).toString());
  18.         }
  19.     }
  20.  
  21.     public void findName(String name) {
  22.         System.out.println();
  23.         System.out.println("Recipes");
  24.         for (int i=0; i<this.recipes.size(); i++) {
  25.             if (this.recipes.get(i).getName().contains(name))
  26.                 System.out.println(this.recipes.get(i).toString());
  27.         }
  28.  
  29.         System.out.println();
  30.     }
  31.  
  32.     public void findCookingTime(int time) {
  33.         System.out.println();
  34.         System.out.println("Recipes");
  35.         for (int i=0; i<this.recipes.size(); i++) {
  36.             if (this.recipes.get(i).getCookingTime() <= time)
  37.             System.out.println(this.recipes.get(i).toString());
  38.         }
  39.     }
  40.  
  41.     public void findIngredient(String name) {
  42.         System.out.println();
  43.         System.out.println("Recipes: ");
  44.         for (int i=0; i<this.recipes.size(); i++) {
  45.             if (this.recipes.get(i).containsIngredient(name))
  46.                 System.out.println(this.recipes.get(i).toString());
  47.         }
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement