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;
}
}
まあ...何が問題なのでしょう、ジェイソン? –
'double'ではなく' int'または 'long'を使用しますか? –