473,387 Members | 1,528 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,387 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 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

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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.