Kaynağa Gözat

Fineto I think that means finished?

Akeem Cherry 6 yıl önce
ebeveyn
işleme
585382da08

+ 21
- 5
src/main/java/com/zipcodewilmington/phone/PhoneNumberFactory.java Dosyayı Görüntüle

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[] 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
      * @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
+        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
      * @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 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
      * @return a new phone number object
60
      * @return a new phone number object
47
      * @throws InvalidPhoneNumberFormatException - thrown if phoneNumberString does not match acceptable format
61
      * @throws InvalidPhoneNumberFormatException - thrown if phoneNumberString does not match acceptable format
48
      */ // TODO - Add throws statement to method signature
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 Dosyayı Görüntüle

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