从方法返回false到主参数

时间:2018-10-27 20:03:28

标签: methods boolean

我似乎无法获得返回false并给出“未找到产品”语句的方法。如果我输入的产品不在目录中。对于任何产品,无论是否在目录中,它都会自动返回true。我只发布了此处理方法和主要参数,因为它不允许我发布这么长的程序。任何帮助将不胜感激!

public static boolean getOrder(String productsCatalog){
    System.out.print("Enter the product name: ");
    Scanner in = new Scanner(System.in);
    String product = in.next();
    if (productsCatalog.contains(product)){
        return true;
    }
    else {
        return false;
    }
}

public static void main(String[] args) {
    bannerPrinter();
    String productsCatalog = productsBuilder();
    boolean productAvailable = getOrder(productsCatalog);
    if (productAvailable == true){
        double price = getPrice();
        double tax = getTax(price);
        double saleTotal = getTotal(price, tax);
        printTotal(saleTotal);
    }
    else if (productAvailable == false) {
        System.out.println("The product was not found.");
    }
}

0 个答案:

没有答案