|
@@ -0,0 +1,65 @@
|
|
1
|
+-
|
|
2
|
+-
|
|
3
|
+#ZCW-MicroLabs-ExceptionsAndLogging
|
|
4
|
+
|
|
5
|
+-
|
|
6
|
+#PhoneNumberFactory
|
|
7
|
+* **Purpose** - to demonstrate basic exception handling and logging.
|
|
8
|
+* **Objective** - to implement a `PhoneNumberFactory` class that generates `PhoneNumber` objects.
|
|
9
|
+* The `PhoneNumber` class is a container for a `String` representation of a respective phone number.
|
|
10
|
+* Note: Phone numbers are a composite of 3 affixes; `Area Code`, `Central Office Code`, and `Phone Line Code`.
|
|
11
|
+ * `Area Code` - the first 3 numeric values
|
|
12
|
+ * `Central Office Code` - the 4th, 5th, and 6th numeric values.
|
|
13
|
+ * `Phone Line Code` - the last 3 numeric values.
|
|
14
|
+
|
|
15
|
+* Below is a sample *instantation of* and *invokation on* `PhoneNumber`.
|
|
16
|
+
|
|
17
|
+```Java
|
|
18
|
+String stringRepresentation = "(302)-312-5555)";
|
|
19
|
+PhoneNumber phoneNumber = new PhoneNumber(stringRepresentation);
|
|
20
|
+String areaCode = phoneNumber.getAreaCode();
|
|
21
|
+String centralOfficeCode = phoneNumber.getCentralOfficeCode();
|
|
22
|
+String phoneLineCode = phoneNumber.getPhoneLineCode();
|
|
23
|
+```
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+-
|
|
27
|
+#Part 1; Modify `createPhoneNumber`
|
|
28
|
+* 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>
|
|
29
|
+* `InvalidPhoneNumberFormatException` extends `IOException`, which is a `checked exception`.<br>
|
|
30
|
+* Modify the `createPhoneNumber` method so that it throws any resulting `InvalidPhoneNumberFormatException`.
|
|
31
|
+ * This will ensure that any method calling `createPhoneNumber` will have to handle the exception.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+-
|
|
36
|
+#Part 2; Implement `createPhoneNumberSafely`
|
|
37
|
+* 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.
|
|
38
|
+* Use this `String` object to construct a new instance of `PhoneNumber` and return it.
|
|
39
|
+* 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
|
+* If a `InvalidPhoneNumberFormatException` is thrown within this method, catch it and return `null`.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+-
|
|
44
|
+#Part 3; Implement `createRandomPhoneNumber`
|
|
45
|
+* 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.
|
|
46
|
+
|
|
47
|
+-
|
|
48
|
+#Part 4; Implement `createRandomPhoneNumberArray`
|
|
49
|
+* Using the `createRandomPhoneNumber` from `Part 3`, generate an array of `PhoneNumber` objects, whose length reflects the input argument.
|
|
50
|
+ * For example `createRandomPhoneNumber(5)` should return an array of 5 `PhoneNumber` objects.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+-
|
|
54
|
+#Part 5; Add logging
|
|
55
|
+* Add logging to the `createPhoneNumber` method from `Part 1`, which logs the message
|
|
56
|
+ * `"Attempting to create a new PhoneNumber object with a value of (###)-###-####`
|
|
57
|
+ * where `(###)-###-####` will be replaced with the respective input parameter.
|
|
58
|
+
|
|
59
|
+* Add logging to the `createPhoneNumberSafely` method from `Part 2`, which logs the message
|
|
60
|
+ * `(###)-###-#### is not a valid phone number`
|
|
61
|
+ * Where `(###)-###-####` will be replaced with the respective input parameter.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+#Part 6; Ensure all test cases pass
|
|
65
|
+* Yeah this header says all that is needed...
|