|
@@ -2,6 +2,8 @@ package com.zipcodewilmington.phone;
|
2
|
2
|
|
3
|
3
|
import com.zipcodewilmington.exceptions.InvalidPhoneNumberFormatException;
|
4
|
4
|
|
|
5
|
+import java.lang.reflect.Array;
|
|
6
|
+import java.util.ArrayList;
|
5
|
7
|
import java.util.logging.Logger;
|
6
|
8
|
|
7
|
9
|
/**
|
|
@@ -20,14 +22,23 @@ public final class PhoneNumberFactory {
|
20
|
22
|
* @return array of randomly generated PhoneNumber objects
|
21
|
23
|
*/ //TODO - Implement logic
|
22
|
24
|
public static PhoneNumber[] createRandomPhoneNumberArray(int phoneNumberCount) {
|
23
|
|
- return null;
|
|
25
|
+ ArrayList<PhoneNumber> phone = new ArrayList();
|
|
26
|
+ phone.add(createRandomPhoneNumber(phoneNumberCount));
|
|
27
|
+ PhoneNumber [] number = (PhoneNumber[]) phone.toArray();
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+ return number;
|
24
|
31
|
}
|
25
|
32
|
|
26
|
33
|
/**
|
27
|
34
|
* @return an instance of PhoneNumber with randomly generated phone number value
|
28
|
35
|
*/ //TODO - Implement logic
|
29
|
|
- public static PhoneNumber createRandomPhoneNumber() {
|
30
|
|
- return createPhoneNumberSafely(-1, -1, -1);
|
|
36
|
+ public static PhoneNumber createRandomPhoneNumber(int numbers) {
|
|
37
|
+ double number = Math.floor(100+Math.random()*900);
|
|
38
|
+ double number2 = Math.floor(1000+Math.random()*9000);
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+ return createPhoneNumberSafely((int)number, (int)number, (int)number2);
|
31
|
42
|
}
|
32
|
43
|
|
33
|
44
|
|
|
@@ -38,7 +49,16 @@ public final class PhoneNumberFactory {
|
38
|
49
|
* @return a new phone number object
|
39
|
50
|
*/ //TODO - if input is valid, return respective PhoneNumber object, else return null
|
40
|
51
|
public static PhoneNumber createPhoneNumberSafely(int areaCode, int centralOfficeCode, int phoneLineCode) {
|
41
|
|
- return createPhoneNumber(null);
|
|
52
|
+ try {
|
|
53
|
+ String phoneNumber = "(" + areaCode + ")-" + centralOfficeCode + "-" + phoneLineCode;
|
|
54
|
+ return createPhoneNumber(phoneNumber);
|
|
55
|
+ }catch (InvalidPhoneNumberFormatException e) {
|
|
56
|
+ logger.finest("(###)-###-#### is not a valid phone number");
|
|
57
|
+ e.printStackTrace();
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ return null;
|
|
61
|
+
|
42
|
62
|
}
|
43
|
63
|
|
44
|
64
|
/**
|
|
@@ -46,7 +66,9 @@ public final class PhoneNumberFactory {
|
46
|
66
|
* @return a new phone number object
|
47
|
67
|
* @throws InvalidPhoneNumberFormatException - thrown if phoneNumberString does not match acceptable format
|
48
|
68
|
*/ // TODO - Add throws statement to method signature
|
49
|
|
- public static PhoneNumber createPhoneNumber(String phoneNumberString) {
|
50
|
|
- return null;
|
|
69
|
+ public static PhoneNumber createPhoneNumber(String phoneNumberString) throws InvalidPhoneNumberFormatException {
|
|
70
|
+ PhoneNumber number = new PhoneNumber(phoneNumberString);
|
|
71
|
+ logger.finest("Attempting to create a new PhoneNumber object with a value of (###)-###-####");
|
|
72
|
+ return number;
|
51
|
73
|
}
|
52
|
74
|
}
|