Advertisement
Mmmag2

Untitled

Apr 21st, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.nio.file.Paths;
  3. import java.util.ArrayList;
  4.  
  5. public class UserInput {
  6.  
  7. private ArrayList<Recipe> recipes;
  8.  
  9. public UserInput(){
  10.  
  11. }
  12.  
  13. public void start(Scanner scanner){
  14.  
  15. System.out.println("File to read:");
  16. String file = scanner.nextLine();
  17. try (Scanner reader = new Scanner(Paths.get(file))){
  18. while(reader.hasNextLine()){
  19. String name = reader.nextLine();
  20. int time = Integer.valueOf(reader.nextLine());
  21. ArrayList<String> ingredients = new ArrayList<String>();
  22. Recipe recipe = new Recipe(name, time);
  23. while(reader.hasNextLine()){
  24. String ing = reader.nextLine();
  25. if(ing.isBlank()){
  26. break;
  27. }
  28. ingredients.add(ing);
  29. }
  30. recipe.addRecipe(ingredients);
  31. recipes.add(recipe);
  32. }
  33. } catch (Exception e){
  34. System.out.println("Error: " + e.getMessage());
  35. }
  36.  
  37. }
  38.  
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement