Samorokimetal

Recipe_Book 19.11.2020

Nov 22nd, 2020 (edited)
567
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2.  
  3. public class Recipe_Book {
  4.     private ArrayList<Recipe> recipes = new ArrayList<>();
  5.  
  6.     public Recipe findCheapestRecipe() {
  7.         Recipe cheapestRecipe = recipes.get(0);
  8.         for (int i = 0; i < recipes.size(); i++) {
  9.             if (recipes.get(i).getPrice() < cheapestRecipe.getPrice()) {
  10.                 cheapestRecipe = recipes.get(i);
  11.             }
  12.         }
  13.         return cheapestRecipe;
  14.     }
  15.  
  16.     public Recipe findFastestRecipe() {
  17.         Recipe fastestRecipe = recipes.get(0);
  18.         for (int i = 0; i < recipes.size(); i++) {
  19.             if (recipes.get(i).timeInMinutes() < fastestRecipe.timeInMinutes()) {
  20.                 fastestRecipe = recipes.get(i);
  21.             }
  22.         }
  23.         return fastestRecipe;
  24.     }
  25.  
  26.     public ArrayList getRecipes() {
  27.         return recipes;
  28.     }
  29.  
  30.     public void addRecipe(Recipe recipe) {
  31.         this.recipes.add(recipe);
  32.     }
  33. }
RAW Paste Data