Upon instantiating a new 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.
Modify the createPhoneNumber method so that it throws any resulting InvalidPhoneNumberFormatException.
This will ensure that any method calling createPhoneNumber will have to handle the exception.
Part 2; Implement createPhoneNumberSafely
Using the 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.
Use this String object to construct a new instance of PhoneNumber and return it.
If the concatentation of the input parameters yields a String whose value does not match the format (###)-###-####, then our PhoneNumber will throw a InvalidPhoneNumberFormatException.
If a InvalidPhoneNumberFormatException is thrown within this method, catch it and return null.
Part 3; Implement createRandomPhoneNumber
Using the 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.
Part 4; Implement createRandomPhoneNumberArray
Using the createRandomPhoneNumber from Part 3, generate an array of PhoneNumber objects, whose length reflects the input argument.
For example createRandomPhoneNumber(5) should return an array of 5 PhoneNumber objects.
Part 5; Add logging
Add logging to the createPhoneNumber method from Part 1, which logs the message
"Attempting to create a new PhoneNumber object with a value of (###)-###-####
where (###)-###-#### 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
Where (###)-###-#### will be replaced with the respective input parameter.
请发表评论