2012-03-13 4 views
1

JTextFieldに記載されている金額がプラスであることを確認するにはどうすればよいですか?例:100.19と-49.8は受け入れられません。彼らはまだ同じ数であればダウン番号とチェックを丸めcomputeBalance()メソッドをmdifyして、金額が正でセントでなくなるようにしますか?

public class ATMbizlogic { 

    private double totalBalance; 
    private boolean rightPinEntered; 



    /** 
    * Creates a new instance of ATMbizlogic 
    */ 
    public ATMbizlogic() 
    { 
     totalBalance = 0.0; 
     rightPinEntered = true; 
    } 

    public void computeBalance(double withdraw, double deposit) 
    throws ATMexception 
    { 
     if(withdraw <=0) 
      throw new ATMexception("Negative withdraw not allowed"); 


     if(deposit <=0) 
      throw new ATMexception("Negative deposit not allowed"); 


     double balance = deposit - withdraw; 

     totalBalance = totalBalance + balance; 



    } 



    public void checkPin(double pin) 
    throws ATMexception 
    { 
     if(pin <=0) 
      throw new ATMexception("Negative pin not allowed"); 
     if(rightPinEntered == false) 
      throw new ATMexception("Can not take another pin"); 
     if(pin<1111 || pin>9999) 
      throw new ATMexception("Enter a valid pin"); 
     rightPinEntered = true; 


    } 




    public double getBalance() 
    { 
     return totalBalance; 
    } 
} 
+0

まあ...何が問題なのでしょう、ジェイソン? –

+0

'double'ではなく' int'または 'long'を使用しますか? –

答えて

2
if(floor(withdraw) != withdraw) 
    throw new ATMexception("Withdraw with cents is not allowed."); 

if(floor(deposit) != deposit) 
    throw new ATMexception("Deposit with cents is not allowed."); 

。そうでなければ、小数点を持っていたことを意味します。

関連する問題