- #1
Ocasta
- 40
- 0
Homework Statement
Problem:
Tele-Annoy, a telemarketing company has asked you to write a program that when given the area code to dial, generates the next three potential telephone numbers, and then outputs them to the screen for one of their sales representatives to call. Use the area code as the seed for the randomly generated numbers.
Code:
Please enter the area code: [B]860[/B]
First number to call - (860)033-8869
Second number to call - (860)367-7868
Third number to call - (860)206-1751
hint: The order you generate random numbers matters! If you use the input above, you should get the same numbers!
The Attempt at a Solution
Here's what I have so far:
Code:
import java.util.Scanner ;
import java.util.Random ;
import java.text.DecimalFormat ;
public class PhoneNumberGenerator
{
public static void main ( String[] args )
{
int area ;
int number ;
Scanner s = new Scanner( System.in ) ;
DecimalFormat df = new DecimalFormat( "000-0000" );
System.out.println("Please enter the area code: ");
// This gets the area code input from the user, but right now it's being occupied by 860 for debugging.
//area = s.nextInt();
area = 860 ;
Random r = new Random( area ) ;
// Test to makes sure I get the right output. Delete!
System.out.println(area) ;
number = r.nextInt( 10000000 ) ;
System.out.println("First number to call - (" + area + ")" + df.format( number ) );
number = r.nextInt( 10000000 ) ;
System.out.println("Second number to call - (" + area + ")" + df.format( number ) );
number = r.nextInt( 10000000 ) ;
System.out.println("Third number to call - (" + area + ")" + df.format( number ) );
}
}
As it stands I keep getting this:
Code:
Please enter the area code:
860 (note, this is a test to make sure I'm using the correct area code and seed)
First number to call - (860)8951033-
Second number to call - (860)5958869-
Third number to call - (860)3561367-
Last edited: