|
|
@@ -2,6 +2,7 @@ package com.zipcodewilmington.phone;
|
|
2
|
2
|
|
|
3
|
3
|
import com.zipcodewilmington.exceptions.InvalidPhoneNumberFormatException;
|
|
4
|
4
|
|
|
|
5
|
+import java.util.Random;
|
|
5
|
6
|
import java.util.logging.Logger;
|
|
6
|
7
|
|
|
7
|
8
|
/**
|
|
|
@@ -19,15 +20,27 @@ public final class PhoneNumberFactory {
|
|
19
|
20
|
* @param phoneNumberCount - number of PhoneNumber objects to instantiate
|
|
20
|
21
|
* @return array of randomly generated PhoneNumber objects
|
|
21
|
22
|
*/ //TODO - Implement logic
|
|
22
|
|
- public static PhoneNumber[] createRandomPhoneNumberArray(int phoneNumberCount) {
|
|
23
|
|
- return null;
|
|
|
23
|
+ public static PhoneNumber[] createRandomPhoneNumberArray(int phoneNumberCount) throws InvalidPhoneNumberFormatException{
|
|
|
24
|
+
|
|
|
25
|
+ PhoneNumber[] phone=new PhoneNumber[phoneNumberCount];
|
|
|
26
|
+ for(int i=0;i<phoneNumberCount;i++ )
|
|
|
27
|
+ {
|
|
|
28
|
+ phone[i]=createRandomPhoneNumber();
|
|
24
|
29
|
}
|
|
25
|
30
|
|
|
|
31
|
+ return phone;
|
|
|
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() {
|
|
|
37
|
+ Random random=new Random();
|
|
|
38
|
+ int areaCode=random.nextInt(900 ) +100;
|
|
|
39
|
+ int centralOfficeCode=random.nextInt(900)+100;
|
|
|
40
|
+ int phoneLineCode=random.nextInt(8990)+1000;
|
|
|
41
|
+ System.out.println("areacode" +areaCode+"\tcentralOfficeCode:"+ centralOfficeCode +"\t phoneLineCode"+phoneLineCode);
|
|
|
42
|
+
|
|
|
43
|
+ return createPhoneNumberSafely(areaCode , centralOfficeCode ,phoneLineCode );
|
|
31
|
44
|
}
|
|
32
|
45
|
|
|
33
|
46
|
|
|
|
@@ -38,15 +51,27 @@ public final class PhoneNumberFactory {
|
|
38
|
51
|
* @return a new phone number object
|
|
39
|
52
|
*/ //TODO - if input is valid, return respective PhoneNumber object, else return null
|
|
40
|
53
|
public static PhoneNumber createPhoneNumberSafely(int areaCode, int centralOfficeCode, int phoneLineCode) {
|
|
41
|
|
- return createPhoneNumber(null);
|
|
|
54
|
+ String phoneNumber="(" + areaCode + ")-" +centralOfficeCode +"-"+phoneLineCode;
|
|
|
55
|
+ try {
|
|
|
56
|
+ PhoneNumber phoneNumber1 = new PhoneNumber(phoneNumber);
|
|
|
57
|
+ return phoneNumber1;
|
|
|
58
|
+
|
|
|
59
|
+ } catch( InvalidPhoneNumberFormatException e)
|
|
|
60
|
+ {
|
|
|
61
|
+ logger.warning("invalid phone number" ) ;
|
|
|
62
|
+ return null;
|
|
42
|
63
|
}
|
|
|
64
|
+}
|
|
43
|
65
|
|
|
44
|
66
|
/**
|
|
45
|
67
|
* @param phoneNumberString - some String corresponding to a phone number whose format is `(###)-###-####`
|
|
46
|
68
|
* @return a new phone number object
|
|
47
|
69
|
* @throws InvalidPhoneNumberFormatException - thrown if phoneNumberString does not match acceptable format
|
|
48
|
70
|
*/ // TODO - Add throws statement to method signature
|
|
49
|
|
- public static PhoneNumber createPhoneNumber(String phoneNumberString) {
|
|
50
|
|
- return null;
|
|
|
71
|
+ public static PhoneNumber createPhoneNumber(String phoneNumberString) throws InvalidPhoneNumberFormatException {
|
|
|
72
|
+ //phoneNumberString ="302-312-5555";
|
|
|
73
|
+ PhoneNumber phone=new PhoneNumber(phoneNumberString );
|
|
|
74
|
+ logger.info("Attempting to create a new PhoneNumber object with a value of " + phone);
|
|
|
75
|
+ return phone;
|
|
51
|
76
|
}
|
|
52
|
77
|
}
|