473,387 Members | 1,528 Online

# creats and prints a random phone number

The question is : 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.

I have done this so far lol :

import java.util.Random;

public class digits {

/**
* @param args
*/
public static void main(String[] args) {

int a;
Random s = new Random();

a = s.nextInt(30);

System.out.println(a);

// TODO Auto-generated method stub

}

}

So if any1 can help that would be great ...thanks.
Sep 4 '07 #1
2 4201
r035198x
13,262 8TB
The question is : 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.

I have done this so far lol :

import java.util.Random;

public class digits {

/**
* @param args
*/
public static void main(String[] args) {

int a;
Random s = new Random();

a = s.nextInt(30);

System.out.println(a);

// TODO Auto-generated method stub

}

}

So if any1 can help that would be great ...thanks.
1.) When posting any code please use code tags.
2.) You need to generate the numbers in sets (first three digits, middle three digits, and last four digits). This means you need to structure your program in a way that reflects that. You ccould even have three methods if you want. generateFirstThree, generateMiddleThree and generateLastFour.
Sep 5 '07 #2
Nepomuk
3,112 Expert 2GB
1.) When posting any code please use code tags.
2.) You need to generate the numbers in sets (first three digits, middle three digits, and last four digits). This means you need to structure your program in a way that reflects that. You ccould even have three methods if you want. generateFirstThree, generateMiddleThree and generateLastFour.
You could alternatively have one Function, that takes two values (max and min) and creates a random value, which lies between both.
Think about how you would use such a function to create a phone number, which fulfilles your needs.

Hint: What you've written until now, can be used in that function - but you'll have to find out how yourself. ^^
Sep 5 '07 #3