donnaj b482e52b88 complete | 6 years ago | |
---|---|---|
src | 6 years ago | |
.gitignore | 7 years ago | |
README.md | 7 years ago | |
pom.xml | 7 years ago |
PhoneNumberFactory
class that generates PhoneNumber
objects.PhoneNumber
class is a container for a String
representation of a respective phone number.Note: Phone numbers are a composite of 3 affixes; Area Code
, Central Office Code
, and Phone Line Code
.
Area Code
- the first 3 numeric valuesCentral Office Code
- the 4th, 5th, and 6th numeric values.Phone Line Code
- the last 4 numeric values.Below is a sample instantation of and invokation on PhoneNumber
.
String stringRepresentation = "(302)-312-5555";
PhoneNumber phoneNumber = new PhoneNumber(stringRepresentation);
String areaCode = phoneNumber.getAreaCode();
String centralOfficeCode = phoneNumber.getCentralOfficeCode();
String phoneLineCode = phoneNumber.getPhoneLineCode();
createPhoneNumber
PhoneNumber
object, it is possible to receive a InvalidPhoneNumberFormatException
if the String
passed into the PhoneNumber
constructor does not fit the format (###)-###-####
.InvalidPhoneNumberFormatException
extends IOException
, which is a checked exception
.createPhoneNumber
method so that it throws any resulting InvalidPhoneNumberFormatException
.
createPhoneNumber
will have to handle the exception.createPhoneNumberSafely
createPhoneNumber
method from Part 1
, define the createPhoneNumberSafely
method such that the input parameters, areaCode
, centralOfficeCode
, phoneLineCode
are concatenated to create a String
representation of the respective phone number.String
object to construct a new instance of PhoneNumber
and return it.String
whose value does not match the format (###)-###-####
, then our PhoneNumber
will throw a InvalidPhoneNumberFormatException
.InvalidPhoneNumberFormatException
is thrown within this method, catch it and return null
.createRandomPhoneNumber
RandomNumberFactory
, generate a random Area Code
, Central Office Code
, and Phone Line Code
. Pass these values as arguments of the createPhoneNumberSafely
method from Part 2
and return the resulting PhoneNumber
object.createRandomPhoneNumberArray
createRandomPhoneNumber
from Part 3
, generate an array of PhoneNumber
objects, whose length reflects the input argument.
createRandomPhoneNumber(5)
should return an array of 5 PhoneNumber
objects.Add logging to the createPhoneNumber
method from Part 1
, which logs the message
"Attempting to create a new PhoneNumber object with a value of (###)-###-####
(###)-###-####
will be replaced with the respective input parameter.Add logging to the createPhoneNumberSafely
method from Part 2
, which logs the message
(###)-###-#### is not a valid phone number
(###)-###-####
will be replaced with the respective input parameter.