Hi again guys, I've been working on a personal project again in Unit 3 of my text book and this time they want me to make a random phone number generator. Here's the actual directions:

"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."

With this assignment I came across 2 problems:

1. What I tried was that since the first 3 numbers have to be a random number with no 8's or 9's I tried doing this algorithm:

int first0, first1, first2, second, third, random0;

first0 = generator.nextInt (999);

random0 = generator.nextInt (8);

first1 = first0.replace('8', random0);

first2 = first1.replace('9' random0);

The problem is that Java won't allow me to generate random numbers this way. Are there any easier ways of generating numbers that doesn't contain specific number (such as 8 or 9 in this case?)

2. I was thinking about this throughout the whole project and what if I generate a number such as 27 (less than 3 or 4 digit number) rather than 3 or 4 digit numbers? How would it show 0027 or 027 instead of 27 for the phone numbers?

P.S. oh by the way I am only in Unit 3 of the text book, which contains "creating objects", "The string class", "packages", "The random class", "The math class", "Formatting Output", and "Enumerated types". Anything beyond that is a problem for me, so if someone can help me with this within my knowledge, I will be greatful.

MY ACTUAL WHOLE PROJECT:

import java.util.Random;

public class pp0303 {

public static void main (String[] args)

{

Random generator = new Random();

int first0, first1, first2, second, third, random0;

first0 = generator.nextInt (999);

random0 = generator.nextInt (8);

first1 = first0.replace('8', random0);

first2 = first1.replace('9' random0);

second = generator.nextInt (743);

third = generator.nextInt (9999);

System.out.println ("Your new phone number is: " + first2 + " - " + second + " - " + third);

}

}

RESULTS:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:

Cannot invoke replace(char, int) on the primitive type int

Cannot invoke replace(char) on the primitive type int

Syntax error on token "random0", delete this token

at pp0303.main(pp0303.java:15)