Advertisement
Guest User

Untitled

a guest
Jun 6th, 2021
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public void addRecipes() {
  2. int index = 0;
  3. String name = "";
  4. int duration = 0;
  5. ArrayList<String> ingredients = new ArrayList<>(); //create new list
  6.  
  7. for (int i = 0; i < data.size(); i++) {
  8. if (index == 0) {
  9. name = data.get(i);
  10. }
  11. if (index == 1) {
  12. duration = Integer.valueOf(data.get(i));
  13.  
  14. }
  15.  
  16. if (index > 1 && !data.get(i).equals("")) { //this adds stuff to arraylist until empty line hit
  17. ingredients.add(data.get(i));
  18.  
  19. }
  20.  
  21. if (data.get(i).equals("") || i == (data.size() - 1)) {
  22. ArrayList<String> tempList = new ArrayList<>(); //creates new arraylist
  23. for (String items : ingredients) {
  24. tempList.add(items); //fills it with values from the main arraylist
  25. }
  26. Recipe recipe = new Recipe(name, duration, tempList); //why does this work when the temp "resets" every loop?
  27. recipeList.addRecipe(recipe);
  28. ingredients.clear();
  29. index = 0;
  30. continue;
  31. }
  32.  
  33. index++;
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement