|
|
|
|
1
|
--
|
|
|
|
|
1
|
+
|
2
|
# ZCW-MicroLabs-ExceptionsAndLogging
|
2
|
# ZCW-MicroLabs-ExceptionsAndLogging
|
3
|
|
3
|
|
4
|
--
|
|
|
|
|
4
|
+
|
5
|
# PhoneNumberFactory
|
5
|
# PhoneNumberFactory
|
6
|
* **Purpose** - to demonstrate basic exception handling and logging.
|
6
|
* **Purpose** - to demonstrate basic exception handling and logging.
|
7
|
* **Objective** - to implement a `PhoneNumberFactory` class that generates `PhoneNumber` objects.
|
7
|
* **Objective** - to implement a `PhoneNumberFactory` class that generates `PhoneNumber` objects.
|
|
|
|
|
22
|
```
|
22
|
```
|
23
|
|
23
|
|
24
|
|
24
|
|
25
|
--
|
|
|
26
|
# Part 1; Modify `createPhoneNumber`
|
25
|
# Part 1; Modify `createPhoneNumber`
|
27
|
* 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 `(###)-###-####`.<br>
|
26
|
* 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 `(###)-###-####`.<br>
|
28
|
* `InvalidPhoneNumberFormatException` extends `IOException`, which is a `checked exception`.<br>
|
27
|
* `InvalidPhoneNumberFormatException` extends `IOException`, which is a `checked exception`.<br>
|
|
|
|
|
31
|
|
30
|
|
32
|
|
31
|
|
33
|
|
32
|
|
34
|
--
|
|
|
35
|
# Part 2; Implement `createPhoneNumberSafely`
|
33
|
# Part 2; Implement `createPhoneNumberSafely`
|
36
|
* 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.
|
34
|
* 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.
|
37
|
* Use this `String` object to construct a new instance of `PhoneNumber` and return it.
|
35
|
* Use this `String` object to construct a new instance of `PhoneNumber` and return it.
|
|
|
|
|
39
|
* If a `InvalidPhoneNumberFormatException` is thrown within this method, catch it and return `null`.
|
37
|
* If a `InvalidPhoneNumberFormatException` is thrown within this method, catch it and return `null`.
|
40
|
|
38
|
|
41
|
|
39
|
|
42
|
--
|
|
|
43
|
# Part 3; Implement `createRandomPhoneNumber`
|
40
|
# Part 3; Implement `createRandomPhoneNumber`
|
44
|
* 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.
|
41
|
* 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.
|
45
|
|
42
|
|
46
|
--
|
|
|
|
|
43
|
+
|
47
|
# Part 4; Implement `createRandomPhoneNumberArray`
|
44
|
# Part 4; Implement `createRandomPhoneNumberArray`
|
48
|
* Using the `createRandomPhoneNumber` from `Part 3`, generate an array of `PhoneNumber` objects, whose length reflects the input argument.
|
45
|
* Using the `createRandomPhoneNumber` from `Part 3`, generate an array of `PhoneNumber` objects, whose length reflects the input argument.
|
49
|
* For example `createRandomPhoneNumber(5)` should return an array of 5 `PhoneNumber` objects.
|
46
|
* For example `createRandomPhoneNumber(5)` should return an array of 5 `PhoneNumber` objects.
|
50
|
|
47
|
|
51
|
|
48
|
|
52
|
--
|
|
|
53
|
# Part 5; Add logging
|
49
|
# Part 5; Add logging
|
54
|
* Add logging to the `createPhoneNumber` method from `Part 1`, which logs the message
|
50
|
* Add logging to the `createPhoneNumber` method from `Part 1`, which logs the message
|
55
|
* `"Attempting to create a new PhoneNumber object with a value of (###)-###-####`
|
51
|
* `"Attempting to create a new PhoneNumber object with a value of (###)-###-####`
|