473,396 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

creats and prints a random phone number

1
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 4204
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

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: lharby | last post by:
I'm hoping this is very simple. I am currently using a random quote generator on our intranet. I have 17 quotes, when I add in an 18th and change the makeArray number the code seems not to work....
7
by: Jean-Francois.Doyon | last post by:
Hello, I'm trying to retrieve a limited number of random rows, and order them by a column, and am not having any luck with that last part: SELECT * FROM tablename ORDER BY random(), id LIMIT...
2
by: deko | last post by:
The below code dials a phone number using C:\Program Files\Windows NT\dialer.exe. The problem is that dialing rules are ignored. MS Knowledge Base Article 266253 suggests that entering the phone...
4
by: darrel | last post by:
I can grab a random number in vb.net like this: Dim RandomClass As New Random Dim RandomNumber As Integer RandomNumber = RandomClass.Next(1, 26) However, what I want is a random number. Short...
7
by: laredotornado | last post by:
Hi, Using php 4.4.4, I am looking to parse a US phone number string into 3 smaller strings -- area code, the first part of the phone number (3 digits) and the last part of the phone number (4...
5
by: lim4801 | last post by:
I am currently in doing a program which is given by my tutor: Contemplate that you are working for the phone company and want to sell "special" phone numbers to companies. These phone numbers are...
2
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I need to add a method to a VB6 OCX that we are consuming with C# (VS 2005) Unfortunately the person that created the original DLL to reference in the C# code is not available. When I create a DLL...
7
by: Propoflady | last post by:
My contacts can have as many as five or six phone numbers - is it possible to make a query that puts the name, and each phone number after it on the same line - for this reason I have two tables -...
10
Frinavale
by: Frinavale | last post by:
I've been experiencing something pretty strange with my phone lately, it appears that sometimes my text messages are sent to random people across the country. I've contacted my cell phone provider...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.