|
|
@@ -1,6 +1,7 @@
|
|
1
|
1
|
package com.zipcodewilmington.phone;
|
|
2
|
2
|
|
|
3
|
3
|
import com.zipcodewilmington.exceptions.InvalidPhoneNumberFormatException;
|
|
|
4
|
+import com.zipcodewilmington.tools.RandomNumberFactory;
|
|
4
|
5
|
|
|
5
|
6
|
import java.util.logging.Logger;
|
|
6
|
7
|
|
|
|
@@ -18,16 +19,20 @@ public final class PhoneNumberFactory {
|
|
18
|
19
|
/**
|
|
19
|
20
|
* @param phoneNumberCount - number of PhoneNumber objects to instantiate
|
|
20
|
21
|
* @return array of randomly generated PhoneNumber objects
|
|
21
|
|
- */ //TODO - Implement logic
|
|
22
|
|
- public static PhoneNumber[] createRandomPhoneNumberArray(int phoneNumberCount) {
|
|
23
|
|
- return null;
|
|
|
22
|
+ */
|
|
|
23
|
+ public static PhoneNumber[] createRandomPhoneNumberArray(int phoneNumberCount) throws InvalidPhoneNumberFormatException{
|
|
|
24
|
+ PhoneNumber[] phoneBook = new PhoneNumber[phoneNumberCount];
|
|
|
25
|
+ for (int i =0; i < phoneBook.length; i++) {
|
|
|
26
|
+ phoneBook[i] = createRandomPhoneNumber();
|
|
|
27
|
+ }
|
|
|
28
|
+ return phoneBook;
|
|
24
|
29
|
}
|
|
25
|
30
|
|
|
26
|
31
|
/**
|
|
27
|
32
|
* @return an instance of PhoneNumber with randomly generated phone number value
|
|
28
|
|
- */ //TODO - Implement logic
|
|
29
|
|
- public static PhoneNumber createRandomPhoneNumber() {
|
|
30
|
|
- return createPhoneNumberSafely(-1, -1, -1);
|
|
|
33
|
+ */
|
|
|
34
|
+ public static PhoneNumber createRandomPhoneNumber() throws InvalidPhoneNumberFormatException{
|
|
|
35
|
+ return createPhoneNumberSafely(RandomNumberFactory.createInteger(100, 999), RandomNumberFactory.createInteger(100, 999), RandomNumberFactory.createInteger(1000, 9999));
|
|
31
|
36
|
}
|
|
32
|
37
|
|
|
33
|
38
|
|
|
|
@@ -36,17 +41,26 @@ public final class PhoneNumberFactory {
|
|
36
|
41
|
* @param centralOfficeCode - 3 digit code
|
|
37
|
42
|
* @param phoneLineCode - 4 digit code
|
|
38
|
43
|
* @return a new phone number object
|
|
39
|
|
- */ //TODO - if input is valid, return respective PhoneNumber object, else return null
|
|
40
|
|
- public static PhoneNumber createPhoneNumberSafely(int areaCode, int centralOfficeCode, int phoneLineCode) {
|
|
41
|
|
- return createPhoneNumber(null);
|
|
42
|
|
- }
|
|
|
44
|
+ */
|
|
|
45
|
+ public static PhoneNumber createPhoneNumberSafely(int areaCode, int centralOfficeCode, int phoneLineCode)
|
|
|
46
|
+ throws InvalidPhoneNumberFormatException{
|
|
43
|
47
|
|
|
44
|
|
- /**
|
|
45
|
|
- * @param phoneNumberString - some String corresponding to a phone number whose format is `(###)-###-####`
|
|
46
|
|
- * @return a new phone number object
|
|
47
|
|
- * @throws InvalidPhoneNumberFormatException - thrown if phoneNumberString does not match acceptable format
|
|
48
|
|
- */ // TODO - Add throws statement to method signature
|
|
49
|
|
- public static PhoneNumber createPhoneNumber(String phoneNumberString) {
|
|
50
|
|
- return null;
|
|
|
48
|
+ try {
|
|
|
49
|
+ String phoneNumber = "(" + areaCode + ")" + "-" + centralOfficeCode + "-" + phoneLineCode;
|
|
|
50
|
+ return createPhoneNumber(phoneNumber);
|
|
|
51
|
+
|
|
|
52
|
+ } catch (InvalidPhoneNumberFormatException e) {
|
|
|
53
|
+ return null;
|
|
|
54
|
+ }
|
|
51
|
55
|
}
|
|
|
56
|
+
|
|
|
57
|
+ /**
|
|
|
58
|
+ * @param phoneNumberString - some String corresponding to a phone number whose format is `(###)-###-####`
|
|
|
59
|
+ * @return a new phone number object
|
|
|
60
|
+ * @throws InvalidPhoneNumberFormatException - thrown if phoneNumberString does not match acceptable format
|
|
|
61
|
+ */
|
|
|
62
|
+ public static PhoneNumber createPhoneNumber (String phoneNumberString) throws InvalidPhoneNumberFormatException {
|
|
|
63
|
+ return new PhoneNumber(phoneNumberString);
|
|
|
64
|
+ }
|
|
|
65
|
+
|
|
52
|
66
|
}
|