Okay, so I'm currently working on a Computer Science project and I'm coming across an error. Whenever I run these two classes, I get an error where it doesn't read the input and just does nothing after my Scanner gives it a value. I'd appreciate some clarification on what I'm doing wrong. Thanks.
public Recipe(String Directions, String RecipeName, int CalorieCount, MethodOfCook H){
directions = Directions;
recipeName = RecipeName;
calorieCount = CalorieCount;
hi = H;
}
public static void RecipeDisplay(){
for(int i = 0; i <= Ingred.size(); i++){
if (Ingred != null){
Recipe.DisplayHelper();
System.out.println("===============================");
System.out.println(recipeName);
System.out.println("===============================");
System.out.println("Directions; " + directions);
System.out.println("Calories; " + calorieCount);
System.out.println("Cooking Method; " + hi );
}
}
}
public static void DisplayHelper(){
int index = 0;
System.out.println("Would you like to add a recipe?(Type YES or NO)");
Scanner wantTo = new Scanner(System.in);
String bad = wantTo.nextLine();
if(bad == "YES"){
index++;
System.out.println("First we'll start with Ingrediants, Input as many as you like");
Recipe.addIngrediants();
Recipe.editIngrediants();
Recipe.removeIngrediants();
System.out.println("Great, now lets name your Recipe;");
Scanner nameDude = new Scanner(System.in);
String yesName = nameDude.nextLine();
yesName = recipeName;
System.out.println("Moving on, Input your Directions;");
Scanner inputDude = new Scanner(System.in);
String bud = inputDude.nextLine();
bud = directions;
System.out.println("Now input a Calorie Count (Numbers Only!)");
Scanner numberMan = new Scanner(System.in);
int jman = numberMan.nextInt();
jman = calorieCount;
System.out.println("Now select an Enum Method;");
System.out.println("Remember your values are;");
Scanner sc = new Scanner(System.in);
MethodOfCook bu = hi;
for (MethodOfCook bum : bu.values())
System.out.println(bum);
// read strings from Scanner - display Algorithm value or throw exception
while(true){
try
{
System.out.print ("Enter value ");
System.out.println("Great, your value is" + bu.valueOf(sc.next()));
Recipe ji = new Recipe(bud, yesName, jman, bu);
System.out.println(ji);
}
catch (IllegalArgumentException m){
System.out.println(" Error: " + m);
}
}
}
else{
System.out.println("Okay thanks.");
}
}
The error is mainly in my DisplayHelper I believe, also I'm trying to link the scanner inputs to my recipe class, so that I can build an ArrayList of recipes in a separate class, thanks in advance! (Sorry for the strange format, it doesn't seem t want to work.)