while-loop等于无法正常工作(java银行账户)

时间:2017-10-14 11:28:50

标签: java loops while-loop

所以我的任务是编写一个银行账户程序,询问你是想要存款还是取款,它要求多少,最后是否要继续,如果不是,它会显示我当前的账户平衡。例如:

存款或取款(0存款,1 - 取款): 多少? 你想继续吗?

余额:XX.XX

当答案是" Y"该程序应循环播放并中断。在"你想退出吗?"。

package Account;

import java.util.Scanner;

public class bankVisit {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        bankAccount account = new bankAccount();

        String respond = "N";

        System.out.print("Deposit or withdraw (0-deposit, 1-withdraw): ");
        int choice = scan.nextInt();

        while (respond.equals("N")) {
            if (choice == 0) {
                System.out.print("Amount: ");
                double total = scan.nextDouble();
                account.credit(total);

                System.out.print("Do you want to quit? ");
                respond = scan.next();
            } else if (choice == 1) {
                System.out.print("Amount: ");
                double total = scan.nextDouble();
                account.withdraw(total);

                System.out.print("Do you want to quit? ");
                respond = scan.next();
            }

            System.out.print("Deposit or withdraw (0-deposit, 1-withdraw): ");
            choice = scan.nextInt();
        }

        System.out.println("Balance: " + account.getBalance());

        scan.close();
    }
}

我让它循环,但我不知道如何让循环退出,并发布我的余额,它保持循环,即使"响应"不等于" N" ..任何想法?我是Java的新手,所以一切都会做。

0 个答案:

没有答案