我的循环没有正确结束

时间:2017-04-06 19:47:43

标签: java loops

//deposit case 
case "deposit":
    JOptionPane.showMessageDialog(null,"We accept the following dollar bills:\n1, 5, 10, 20, 50, 100"
        + "\nPlease insert the bill on the console."
        + "\nEnter any other number to stop depositing."
        ,"Insert Bill",JOptionPane.INFORMATION_MESSAGE);
    System.out.println("Insert bills here.");

    int deposit = keyboard.nextInt();

    int total = 0; 

    while (deposit==1||deposit==5||deposit==10||deposit==20||deposit==50||deposit==100)
    {

        total += deposit;
        //System.out.println(deposit);
        deposit = keyboard.nextInt();
        //System.out.println(deposit);
        keyboard.close();

       // if (deposit!=1||deposit!=5||deposit!=10||deposit!=20||deposit!=50||deposit!=100)
       // {
         //   break;
       // }

    }


    acc.deposit(total);

    JOptionPane.showMessageDialog(null, "You deposited "+total+" dollars."
                                    +"\nThe current balance is: $"+acc.showBalance()
                                    ,"Deposit into Account" ,JOptionPane.WARNING_MESSAGE);
    break;

//withdraw case    
case "withdraw":

    int money = 0;
    String moneyString = JOptionPane.showInputDialog(null,"Please enter amount you want to withdraw"
                                                    ,"Withdraw from Account",JOptionPane.QUESTION_MESSAGE);

    if (moneyString == null||moneyString.length()==0)
    {
        money = 0;
    }
    else {
        money = Integer.parseInt(moneyString);
    }

    acc.withdraw(money);

    break;

2 个答案:

答案 0 :(得分:0)

在您第一次使用扫描仪后,您似乎关闭了扫描仪keyboard,并且再也不打开它。尝试在关闭程序之前或完成所有存款之后关闭扫描仪。

答案 1 :(得分:0)

我想到了这个问题。我在Mac上,我的JOptionPane窗口在我的编辑器后面弹出。对不起,这篇文章没用。