/** * Issues a phone account to a given person. * * @param accountHolderName the name of the account holder * @param accountHolderDob the date of birth of the account holder * @param accountType the type of account required * @return The phone account created for the given person */ public Phone issuePhone(String accountHolderName, Calendar accountHolderDob, String accountType) { if (accountHolderName == null || accountType == null || accountHolderDob == null) { LOG.warning( "Bad parameter sent. name:" + accountHolderName + " account type: " + accountType + " DOB: " + accountHolderDob.toString()); throw new IllegalArgumentException("All parameters must be none null"); } if (accountHolderDob.after(Calendar.getInstance())) { LOG.warning("Date of birth passed was in the future"); throw new IllegalArgumentException("Date of birth cannot not be in the future"); } PhoneAccount pa; if (accountType.equals(PhoneAccountFactory.PAY_AS_YOU_GO)) { Person accountHolder = new Person(accountHolderName, new Date(accountHolderDob.getTimeInMillis())); pa = PhoneAccountFactory.getInstance(getNewPhoneNumber(), accountHolder, accountType); } else if (accountType == PhoneAccountFactory.UNLIMITED) { Calendar ageLimit = Calendar.getInstance(); ageLimit.set(Calendar.YEAR, (ageLimit.get(Calendar.YEAR) - 18)); if (ageLimit.before(accountHolderDob)) { LOG.warning("Customer is not old enough for this account: " + accountHolderName); return null; } else { Person accountHolder = new Person(accountHolderName, new Date(accountHolderDob.getTimeInMillis())); pa = PhoneAccountFactory.getInstance(getNewPhoneNumber(), accountHolder, accountType); } } else { throw new IllegalArgumentException("Invalid Phone Account type"); } LOG.info("New Account Created: " + pa.getNumber().toString()); return new Phone(pa); }