2017-04-06 5 views
-1
//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; 
+1

ループ内の 'keyboard'を' close() 'しないでください... – brso05

答えて

0

終了していないあなたがループの中でそれを最初に使用した後、あなたのスキャナkeyboardを閉じて再度開くことはありませんようです。プログラムを終了する直前に、またはすべての入金が完了した後に、スキャナを閉じてください。

0

問題が発生しました。私はMacで、JOptionPaneのウィンドウはエディタの後ろにポップアップしていました。申し訳ありませんが、この投稿は役に立ちません。