运算符+ =似乎不适用于我的String

时间:2019-12-03 16:36:10

标签: java if-statement compound-assignment

purchasedOrder在末尾打印时为空,但purchasedOrderPrice显示90

我认为if语句与此有关,但是我不知道出了什么问题

    String meal = "";
    String chicken = "";
    String drink = "";
    String drinkSize = "";
    String purchasedOrder = "" ;

    String CHICKEN = "CHICKEN:\n1. Regular \n2. Spicy";`enter code here`
    String DRINK = "DRINK:\n1. Coke \n2. Sprite"; ]
    String DRINK_SIZE = "DRINK SIZE:\n1. Regular \n2. Large";


    int mealPrice = 0;

    System.out.print("Enter: ");
    meal = input.next().toUpperCase();

    switch (meal) {

    case "C1":
        mealPrice += 90;
        System.out.println(CHICKEN);
        chicken = input.next();
        if (chicken == "1")
            purchasedOrder += "1 PC CHICKEN JOY w/ ";
        if (chicken == "2") {
            purchasedOrder += "1 PC CHICKEN JOY Spicy w/ ";
            mealPrice += 2;
        }
        System.out.println(DRINK);
        drink = input.next();
        if (drink == "1" )
            purchasedOrder += "Coke";
        else if (drink == "2")
            purchasedOrder += "Sprite";
        System.out.println(DRINK_SIZE);
        drinkSize = input.next();
        if (drinkSize == "1")
            purchasedOrder += "Regular";
        if (drinkSize == "2") {
            purchasedOrder += "Large";
            mealPrice += 15;
        }

    }

    System.out.println("DISPLAY \n"+purchasedOrder + "\t\t\t" + purchasedOrderPrice);

0 个答案:

没有答案