【发布时间】:2014-04-09 20:13:19
【问题描述】:
- 我有一个程序使用 Luhn 算法验证信用卡号码并引发用户定义的异常。
- 我的 cc_expired_db.xml 包含过期信用卡号列表。
- 我有 cc_stolen_db.xml,其中包含被盗信用卡号的列表。
请查看我的预期输出的pseudo code。
在个别测试中,我设法让 Luhn 算法工作,并在 FAILED 时抛出无效异常。
这是我的代码:
public boolean checkCreditCard(String strCardNumber, double amount, String luhnStatus)
throws ExpiredCreditCardException, InvalidCreditCardException,
StolenCreditCardException {
if(luhnStatus.equals("PASSED")) {
if() { // missing condition for expired
throw new ExpiredCreditCardException();
} else if() { // missing condition for stolen
throw new StolenCreditCardException();
}
} else if(luhnStatus.equals("FAILED")) { // invalid
throw new InvalidCreditCardException();
} else {
payItem(amount);
System.out.print("Thank you for shopping with us!");
}
return true;
}
我已经成功使用written 和read XML 使用教程。
但是,我不确定如何按照我的伪代码中的预期将过期和被盗异常的条件放入 if 语句中。
【问题讨论】:
-
您可以将日期更改为 long 并使用 - 并比较您是否需要 Java 中的 Date Util 我可以发送给您
标签: java xml validation xml-serialization javabeans