2017-04-06 64 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

請勿在循環內關閉(')''鍵盤'... – brso05

回答

0

看起來,您在循環中第一次使用它並從不再打開它後,會關閉掃描儀keyboard。在關閉程序之前或完成所有存款後,嘗試關閉掃描儀。

0

我想出了這個問題。我在Mac上,我的編輯器後面彈出了JOptionPane窗口。對不起,這篇文章沒用。