Last active
December 25, 2015 19:39
-
-
Save imryan/7028889 to your computer and use it in GitHub Desktop.
Generates a random phone number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class Phone | |
| { | |
| public static void main(String[] args) | |
| { | |
| // Declare variables | |
| int areaCode = 0; | |
| int sequence1 = 0, sequence2 = 0; | |
| String number = ""; | |
| areaCode = getRandomAreaCode(); | |
| sequence1 = getFirstSet(); | |
| sequence2 = getSecondSet(); | |
| number = "(" + areaCode + ") - " + sequence1 + " - " + sequence2; | |
| System.out.println(number); | |
| } | |
| public static int getFirstSet() | |
| { | |
| int seq1, seq2; | |
| Random generator = new Random(); | |
| seq1 = generator.nextInt(999) + 100; | |
| return seq1; | |
| } | |
| public static int getSecondSet() | |
| { | |
| int seq1, seq2; | |
| Random generator = new Random(); | |
| seq1 = generator.nextInt(9999) + 1000; | |
| return seq1; | |
| } | |
| public static int getRandomAreaCode() | |
| { | |
| String areaCodeString = ""; | |
| int areaCode = 0; | |
| // Create a new random generator | |
| Random generator = new Random(); | |
| areaCode = generator.nextInt(743) + 100; | |
| areaCodeString = "" + areaCode; | |
| if (areaCodeString.contains("8") || areaCodeString.contains("8")) | |
| { | |
| areaCode = generator.nextInt(100) + 100; | |
| } | |
| return areaCode; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment