need help with Java solution /newbie

Posted by Racket on Stack Overflow See other posts from Stack Overflow or by Racket
Published on 2011-01-01T16:33:41Z Indexed on 2011/01/01 23:54 UTC
Read the original article Hit count: 263

Filed under:
|
|
|

Hi,

I'm new to programming in general so i'm trying to be as specific as possible in this question. There's this book that i'm doing some exercises on. I managed to do more than half of what they say, but it's just one input that I have been struggling to find out.

I'll write the question and thereafter my code,

"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 diigit does not have to be determined separately."

OK, the highlighted sentence is what i'm looking at. Here's my code:

import java.util.Random;
public class PP33 {
public static void main (String[] args) {
    Random rand = new Random();

    int num1, num2, num3;

    num1 = rand.nextInt(900) + 100;
    num2 = rand.nextInt(643) + 100;
    num3 = rand.nextInt(9000) + 1000;

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



}
}

How am I suppose to do this? I'm on chapter 3 so we have not yet discussed if statements etcetera, but Aliases, String class, Packages, Import declaration, Random Class, Math Class, Formatting output (decimal- & numberFormat), Printf, Enumeration & Wrapper classes + autoboxing. So consider answer the question based only on these assumptions, please.

The code doesn't have any errors.

Thank you!

© Stack Overflow or respective owner

Related posts about java

Related posts about homework