我已经阅读了许多有关while循环的文章和页面,等等,我只是不明白在满足以下三个条件之一之前,在哪里放置循环来重复此过程。如果有人可以指向我需要添加一会儿时间的地方,或者其他我将不胜感激的地方,则无需打印任何代码,除非您愿意。

    System.out.print("Customer name: ");
    name=scan.next();
    System.out.print("Customer member level: ");
    level=scan.next();
    if (level.equalsIgnoreCase("Jedi"))
    {
        System.out.print("Current balance: ");
        balance=scan.nextDouble();
        System.out.print("Was the payment made late?: ");
        late=scan.next();
        if (late.equalsIgnoreCase("Yes"))
        {
            double interestLatePayment=(balance*0.02);
            paymentToPrinciple=(balance*0.04);
            totalPayment=(interestLatePayment+paymentToPrinciple);
            percentToPrinciple=100*(paymentToPrinciple/totalPayment);
            percentToInterest=(100-percentToPrinciple);

            System.out.println("\nBill for "+level+" customer "+name);
            System.out.printf("Card Balance: $%1.2f%n", balance);
            System.out.printf("Interest for late payment (2.0%% of principle): $%1.2f%n", interestLatePayment);
            System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
            System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
            System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
            System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
        }
        else if(late.equalsIgnoreCase("No"))
        {
            double interestLatePayment=(balance*0.01);
            paymentToPrinciple=(balance*0.04);
            totalPayment=(interestLatePayment+paymentToPrinciple);
            percentToPrinciple=100*(paymentToPrinciple/totalPayment);
            percentToInterest=(100-percentToPrinciple);

            System.out.println("\nBill for "+level+" customer "+name);
            System.out.printf("Card Balance: $%1.2f%n", balance);
            System.out.printf("Interest for on-time payment (1.0%% of principle): $%1.2f%n", interestLatePayment);
            System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
            System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
            System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
            System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
        }
    }
    if (level.equalsIgnoreCase("Padowan"))
    {
        System.out.print("Current balance: ");
        balance=scan.nextDouble();
        System.out.print("Was the payment made late?: ");
        late=scan.next();
        if (late.equalsIgnoreCase("Yes"))
        {
            double interestLatePayment=(balance*0.028);
            paymentToPrinciple=(balance*0.04);
            totalPayment=(interestLatePayment+paymentToPrinciple);
            percentToPrinciple=100*(paymentToPrinciple/totalPayment);
            percentToInterest=(100-percentToPrinciple);
            lateFee=10;

            System.out.println("\nBill for "+level+" customer "+name);
            System.out.printf("Card Balance: $%1.2f%n", balance);
            System.out.printf("Interest for late payment (2.8%% of principle): $%1.2f%n", interestLatePayment);
            System.out.printf("Late fee: $%1.2f%n", lateFee);
            System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
            System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
            System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
            System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
        }
        else if(late.equalsIgnoreCase("No"))
        {
            double interestLatePayment=(balance*0.018);
            paymentToPrinciple=(balance*0.04);
            totalPayment=(interestLatePayment+paymentToPrinciple);
            percentToPrinciple=100*(paymentToPrinciple/totalPayment);
            percentToInterest=(100-percentToPrinciple);

            System.out.println("\nBill for "+level+" customer "+name);
            System.out.printf("Card Balance: $%1.2f%n", balance);
            System.out.printf("Interest for late payment (1.8%% of principle): $%1.2f%n", interestLatePayment);
            System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
            System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
            System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
            System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
        }
    }
    if (level.equals("Youngling"))
    {
        System.out.print("Current balance: ");
        balance=scan.nextDouble();
        System.out.print("Was the payment made late?: ");
        late=scan.next();
        if (late.equalsIgnoreCase("Yes"))
        {
            double interestLatePayment=(balance*0.035);
            paymentToPrinciple=(balance*0.04);
            totalPayment=(interestLatePayment+paymentToPrinciple);
            percentToPrinciple=100*(paymentToPrinciple/totalPayment);
            percentToInterest=(100-percentToPrinciple);
            lateFee=20;

            System.out.println("\nBill for "+level+" customer "+name);
            System.out.printf("Card Balance: $%1.2f%n", balance);
            System.out.printf("Interest for late payment (3.5%% of principle): $%1.2f%n", interestLatePayment);
            System.out.printf("Late fee: $%1.2f%n", lateFee);
            System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
            System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
            System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
            System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
        }
        else if(late.equalsIgnoreCase("No"))
        {
            double interestLatePayment=(balance*0.025);
            paymentToPrinciple=(balance*0.04);
            totalPayment=(interestLatePayment+paymentToPrinciple);
            percentToPrinciple=100*(paymentToPrinciple/totalPayment);
            percentToInterest=(100-percentToPrinciple);

            System.out.println("\nBill for "+level+" customer "+name);
            System.out.printf("Card Balance: $%1.2f%n", balance);
            System.out.printf("Interest for late payment (2.5%% of principle): $%1.2f%n", interestLatePayment);
            System.out.printf("Minimum payment to principle (4%% of principle): $%1.2f%n", paymentToPrinciple);
            System.out.printf("Minimum total payment (payment and fees): $%1.2f%n", totalPayment);
            System.out.printf("Percent to principle: %1.1f%%n", percentToPrinciple);
            System.out.printf("Percent to interest and fees: %1.1f%%n", percentToInterest);
        }
    }
    else
    {
        System.out.print("Invalid member level. Enter valid member level: ");
    }
}


}

最佳答案

像这样:

String input;
do {
  input = getNewInput(); //replace this with however you get input, probably a scanner
}while (!input.equals("firstcondition") && !input.equals("secondcondition"))

//then after that do whatever you want to with the input now that you know it matches

10-04 11:44
查看更多