소스 검색

Fineto I think that means finished?

Akeem Cherry 6 년 전
부모
커밋
585382da08

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

+ 0
- 4
src/test/java/com/zipcodewilmington/PhoneNumberFactoryTest.java 파일 보기

@@ -4,12 +4,8 @@ import com.zipcodewilmington.exceptions.InvalidPhoneNumberFormatException;
4 4
 import com.zipcodewilmington.phone.PhoneNumber;
5 5
 import com.zipcodewilmington.phone.PhoneNumberFactory;
6 6
 import org.junit.Assert;
7
-import org.junit.Before;
8 7
 import org.junit.Test;
9 8
 
10
-import java.util.logging.Level;
11
-import java.util.logging.Logger;
12
-
13 9
 /**
14 10
  * Created by leon on 5/9/17.
15 11
  */