Skip to content

Instantly share code, notes, and snippets.

@gabrielruiu
Created April 9, 2014 12:06
Show Gist options
  • Save gabrielruiu/10261502 to your computer and use it in GitHub Desktop.
Save gabrielruiu/10261502 to your computer and use it in GitHub Desktop.
public class RunApp {
private List<String> expiredCCList;
private List<String> stolenCCList;
public Main {
populateExpiredList();
populateStolenList();
}
public boolean checkCreditCard(String strCardNumber, double amount, String luhnStatus) ExpiredCreditCardException, InvalidCreditCardException, {
if(luhnStatus.equals("PASSED")) {
if(expiredCCList.contains(strCardNumber)) {
throw new ExpiredCreditCardException();
} else if(stolenCCList.contains(strCardNumber) {
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;
}
private void populateExpiredList() {
expiredCCList = new ArrayList<String>();
while (reading_CC_Expired.xml) {
String expiredCC = readEntryFromExpiredXML();
expiredCCList.add(expiredCC);
}
}
private void populateStolenList() {
stolenCCList = new ArrayList<String>();
while (reading_CC_Stolen.xml) {
String stolenCC = readEntryFromStolenXML();
stolenCCList.add(stolenCC);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment