2017-04-06 63 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窗口。对不起,这篇文章没用。