Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.nio.file.Paths;
- import java.util.ArrayList;
- public class UserInput {
- private ArrayList<Recipe> recipes;
- public UserInput(){
- }
- public void start(Scanner scanner){
- System.out.println("File to read:");
- String file = scanner.nextLine();
- try (Scanner reader = new Scanner(Paths.get(file))){
- while(reader.hasNextLine()){
- String name = reader.nextLine();
- int time = Integer.valueOf(reader.nextLine());
- ArrayList<String> ingredients = new ArrayList<String>();
- Recipe recipe = new Recipe(name, time);
- while(reader.hasNextLine()){
- String ing = reader.nextLine();
- if(ing.isBlank()){
- break;
- }
- ingredients.add(ing);
- }
- recipe.addRecipe(ingredients);
- recipes.add(recipe);
- }
- } catch (Exception e){
- System.out.println("Error: " + e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement