如何直接将Scanner输入输入If语句?

时间:2019-03-12 00:09:03

标签: java

我在这里有代码,试图将其输入If语句中,特别是在询问“您想要什么?”的部分。我正在尝试从Items = keyboard.nextLine获取输入,以将其转换为If语句if ( == "Hotdog, Brat, Hamburger, Fries, Soda")。我怎样才能做到这一点?我也想知道如何将价格与商品相关联,但这是另一回事。

package NonGUI;
import java.util.Scanner;

public class NewCalc {
    public static void main(String[] args)
    {
        var Items = "Hotdog, Brat, Hamburger, Fries, Soda";
        var Prices = "2.50, 3.50, 5.00, 2.00, 2.00";
        var States = "NJ, NC";
        double price;
        double quantity;
        double tax;
        double total;
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Hotdog, Brat, Hamburger, Fries, Soda");
        System.out.print("What would you like? ");
        Items = keyboard.nextLine();
        if ( == "Hotdog, Brat, Hamburger, Fries, Soda") {
            System.out.println("How many?");
            quantity = keyboard.nextDouble();
            if (quantity > 0) {
                System.out.println("That is too less. Please enter a number larger than 0");
            }else {
                System.out.println("Successfully added to cart!");
            }
            System.out.println("What state do you live in?");
            States = keyboard.nextLine();
            if (States == "NJ, NC") {
                System.out.println("Successfully applied tax.");
            }else {
                System.out.println("Invalid State. Quitting...");
            }
        }else {
            System.out.println("That is not a valid option. Quitting...");
        }
    }
}

0 个答案:

没有答案