I'm currently trying to create a little program which creates Recipes as csv files. That worked fine till the point where I want to add an Ingredient with spaces in between for example: 'real big bananas'. Whenever I write something like this or with underscores or with minus it enters null instead of the word I wrote. I have a class Ingredients(double amount, String unit, String ingredient, String tags) with getter and setters for all of the variables. My Code for creating a csv
public static ArrayList<Ingredients> createIngredientList() {
Scanner scan = new Scanner(System.in);
ArrayList<Ingredients> list = new ArrayList<Ingredients>();
char quit = 'Y';
String unit, ingredient, tags;
double amount;
while(quit == 'Y') {
System.out.print("Please use underscores instead of spaces e.g. real_big_boats.\n");
System.out.print("Amount: ");
amount = scan.nextDouble();
System.out.print("Unit: ");
unit = scan.next();
System.out.print("Ingredient: ");
ingredient = scan.nextLine();
System.out.print("Tags (e.g. tag;tag;tag): ");
tags = scan.nextLine();
list.add(new Ingredients(amount, unit, ingredient, tags));
System.out.print("More Ingredients? (Y/N) ");
String s = scan.next();
s = s.toUpperCase();
quit = s.charAt(0);
}
return list;
}
You can find the whole class in my pastebin below. https://pastebin.com/vi09kGqi