如果声明没有响应扫描仪输入?

时间:2015-11-09 14:12:37

标签: java

好的,所以我目前正在从事计算机科学项目,我遇到了一个错误。每当我运行这两个类时,我会收到一个错误,它没有读取输入,只是在我的Scanner给它一个值之后什么也没做。我很欣赏我做错了什么。感谢。

 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.");
     }
}

错误主要在我的DisplayHelper中我相信,我也试图将扫描仪输入链接到我的食谱类,这样我就可以在一个单独的类中构建一个食谱ArrayList,提前感谢! (对不起奇怪的格式,它似乎不想工作。)

0 个答案:

没有答案