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