Results 1 to 2 of 2
  1. #1
    Garfm is offline Member
    Join Date
    Sep 2013
    Location
    Minnesota
    Posts
    1
    Rep Power
    0

    Default Need help with random phone number generator

    Ok so the project says to "Write an application that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashes in the output. Do not let the first three digits contain an 8 or 9 (but don't be more restrictive than that), and make sure that the second set of three digits is not greater than 742. Hint: Think through the easiest way to construct the phone number. Each digit does not have to be determined separately."

    So the problem I run into in trying to not determine each digit separately is that zeros will not appear before a number for example if it picks 95 as a random number it prints 95 and I want it to be printed 095. I also tried replacing spaces in a printf statement with 0's and i could not get that to work.

    Did some looking around at other forums and it seems like this would be very hard with my limited knowledge in java so far and realized that my first three digits could have 8s and 9s in it. I am guessing i will be solving this by doing each digit separately for now but if there is a simpler solution that anyone has to offer that would be awesome

    Any help would be very appreciated

    Program as it stands right now:

    package programmingProjects8_13;

    //Programming Project 2.13

    import java.util.Random;

    public class PhoneNumbers {

    public static void main(String[] args) {
    Random rand = new Random();
    int num1, num2, num3;

    num1 = rand.nextInt(778);
    num2 = rand.nextInt(743);
    num3 = rand.nextInt(10000);



    System.out.println("Random phone number "+num1+"-"+num2+"-"+num3);


    }

    }
    Last edited by Garfm; 09-15-2013 at 01:37 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Need help with random phone number generator

    first three digits contain an 8 or 9
    If you could work with and display a number in base 8 that would guarantee that none of the digits in the number would be an 8 or 9. The numbers could range from 100 to 777.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Random Phone number generator
    By elecleoalune in forum New To Java
    Replies: 15
    Last Post: 05-19-2014, 01:37 PM
  2. Random number generator
    By adjit in forum New To Java
    Replies: 9
    Last Post: 03-05-2012, 05:09 PM
  3. Need your opinions on my "Random phone number generator"
    By silverglade in forum New To Java
    Replies: 18
    Last Post: 05-14-2011, 07:02 PM
  4. Random number generator
    By zerwik in forum New To Java
    Replies: 3
    Last Post: 12-26-2010, 01:10 PM
  5. Random number generator
    By Michailangelo in forum Advanced Java
    Replies: 4
    Last Post: 04-02-2010, 07:47 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •