浏览代码

Merge 2276655485d95c21be30d7732cebbbffec2a17c4 into 0665dd6f3de2bb92a7f856bde34efac87df0531f

JoeHendricks415 8 年前
父节点
当前提交
dbf94f6a1d
没有帐户链接到提交者的电子邮件

+ 1
- 0
src/main/java/com/zipcodewilmington/exceptions/InvalidPhoneNumberFormatException.java 查看文件

@@ -4,4 +4,5 @@ package com.zipcodewilmington.exceptions;
4 4
  * Created by leon on 5/10/17.
5 5
  */ // Checked Exception
6 6
 public final class InvalidPhoneNumberFormatException extends Exception {
7
+
7 8
 }

+ 25
- 5
src/main/java/com/zipcodewilmington/phone/PhoneNumberFactory.java 查看文件

@@ -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
 
@@ -20,14 +21,24 @@ public final class PhoneNumberFactory {
20 21
      * @return array of randomly generated PhoneNumber objects
21 22
      */ //TODO - Implement logic
22 23
     public static PhoneNumber[] createRandomPhoneNumberArray(int phoneNumberCount) {
23
-        return null;
24
+        PhoneNumber[] phoneNumbs = new PhoneNumber[phoneNumberCount];
25
+
26
+        for(int i = 0; i < phoneNumbs.length; i++){
27
+            phoneNumbs[i] = createRandomPhoneNumber();
28
+        }
29
+        return phoneNumbs;
24 30
     }
25 31
 
26 32
     /**
27 33
      * @return an instance of PhoneNumber with randomly generated phone number value
28 34
      */ //TODO - Implement logic
29 35
     public static PhoneNumber createRandomPhoneNumber() {
30
-        return createPhoneNumberSafely(-1, -1, -1);
36
+
37
+        int areaCode = RandomNumberFactory.createInteger(100, 999);
38
+        int centralOfficeCode = RandomNumberFactory.createInteger(100, 999);
39
+        int phoneLineCode = RandomNumberFactory.createInteger(1000, 9999);
40
+
41
+        return createPhoneNumberSafely(areaCode, centralOfficeCode, phoneLineCode);
31 42
     }
32 43
 
33 44
 
@@ -38,7 +49,15 @@ 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
+        StringBuilder phoneNumberFormat = new StringBuilder();
53
+        phoneNumberFormat.append("(" + areaCode + ")-" + centralOfficeCode + "-" + phoneLineCode);
54
+
55
+        try{
56
+            return createPhoneNumber(phoneNumberFormat.toString());
57
+        } catch (InvalidPhoneNumberFormatException IPFE){
58
+            logger.warning(areaCode + "-" + centralOfficeCode + "-" + phoneLineCode + " is not a valid number!");
59
+            return null;
60
+        }
42 61
     }
43 62
 
44 63
     /**
@@ -46,7 +65,8 @@ public final class PhoneNumberFactory {
46 65
      * @return a new phone number object
47 66
      * @throws InvalidPhoneNumberFormatException - thrown if phoneNumberString does not match acceptable format
48 67
      */ // TODO - Add throws statement to method signature
49
-    public static PhoneNumber createPhoneNumber(String phoneNumberString) {
50
-        return null;
68
+    public static PhoneNumber createPhoneNumber(String phoneNumberString) throws InvalidPhoneNumberFormatException {
69
+        logger.info("Attempting to create a new PhoneNumber object with a value of " + phoneNumberString);
70
+        return new PhoneNumber(phoneNumberString);
51 71
     }
52 72
 }

+ 2
- 0
src/main/java/com/zipcodewilmington/tools/RandomNumberFactory.java 查看文件

@@ -11,11 +11,13 @@ public abstract class RandomNumberFactory {
11 11
 
12 12
     /** @return a random float between the specified min and max numeric range */
13 13
     public static Float createFloat(float min, float max) {
14
+
14 15
         return random.nextFloat() * (max - min) + min;
15 16
     }
16 17
 
17 18
     /** @return a random integer between the specified min and max numeric range */
18 19
     public static Integer createInteger(Integer min, Integer max) {
20
+
19 21
         return createFloat(min, max).intValue();
20 22
     }
21 23
 }