|
|
|
|
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.
|
8
|
* The `PhoneNumber` class is a container for a `String` representation of a respective phone number.
|
8
|
* The `PhoneNumber` class is a container for a `String` representation of a respective phone number.
|
|
|
|
|
23
|
|
23
|
|
24
|
|
24
|
|
25
|
-
|
25
|
-
|
26
|
-#Part 1; Modify `createPhoneNumber`
|
|
|
|
|
26
|
+# 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>
|
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>
|
28
|
* `InvalidPhoneNumberFormatException` extends `IOException`, which is a `checked exception`.<br>
|
28
|
* `InvalidPhoneNumberFormatException` extends `IOException`, which is a `checked exception`.<br>
|
29
|
* Modify the `createPhoneNumber` method so that it throws any resulting `InvalidPhoneNumberFormatException`.
|
29
|
* Modify the `createPhoneNumber` method so that it throws any resulting `InvalidPhoneNumberFormatException`.
|
|
|
|
|
32
|
|
32
|
|
33
|
|
33
|
|
34
|
-
|
34
|
-
|
35
|
-#Part 2; Implement `createPhoneNumberSafely`
|
|
|
|
|
35
|
+# 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.
|
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.
|
37
|
* Use this `String` object to construct a new instance of `PhoneNumber` and return it.
|
37
|
* Use this `String` object to construct a new instance of `PhoneNumber` and return it.
|
38
|
* If the concatentation of the input parameters yields a `String` whose value does not match the format `(###)-###-####`, then our `PhoneNumber` will throw a `InvalidPhoneNumberFormatException`.
|
38
|
* If the concatentation of the input parameters yields a `String` whose value does not match the format `(###)-###-####`, then our `PhoneNumber` will throw a `InvalidPhoneNumberFormatException`.
|
|
|
|
|
40
|
|
40
|
|
41
|
|
41
|
|
42
|
-
|
42
|
-
|
43
|
-#Part 3; Implement `createRandomPhoneNumber`
|
|
|
|
|
43
|
+# 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.
|
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.
|
45
|
|
45
|
|
46
|
-
|
46
|
-
|
47
|
-#Part 4; Implement `createRandomPhoneNumberArray`
|
|
|
|
|
47
|
+# Part 4; Implement `createRandomPhoneNumberArray`
|
48
|
* Using the `createRandomPhoneNumber` from `Part 3`, generate an array of `PhoneNumber` objects, whose length reflects the input argument.
|
48
|
* 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.
|
49
|
* For example `createRandomPhoneNumber(5)` should return an array of 5 `PhoneNumber` objects.
|
50
|
|
50
|
|
51
|
|
51
|
|
52
|
-
|
52
|
-
|
53
|
-#Part 5; Add logging
|
|
|
|
|
53
|
+# Part 5; Add logging
|
54
|
* Add logging to the `createPhoneNumber` method from `Part 1`, which logs the message
|
54
|
* 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 (###)-###-####`
|
55
|
* `"Attempting to create a new PhoneNumber object with a value of (###)-###-####`
|
56
|
* where `(###)-###-####` will be replaced with the respective input parameter.
|
56
|
* where `(###)-###-####` will be replaced with the respective input parameter.
|
|
|
|
|
60
|
* Where `(###)-###-####` will be replaced with the respective input parameter.
|
60
|
* Where `(###)-###-####` will be replaced with the respective input parameter.
|
61
|
|
61
|
|
62
|
|
62
|
|
63
|
-#Part 6; Ensure all test cases pass
|
|
|
|
|
63
|
+# Part 6; Ensure all test cases pass
|
64
|
* Yeah this header says all that is needed...
|
64
|
* Yeah this header says all that is needed...
|