aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Setting a Range Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Setting a Range" Watch "Setting a Range" New topic
Author

Setting a Range

Tony Spedaliere
Greenhorn

Joined: Sep 22, 2004
Posts: 2
i have an input that request a 3-digit number. I want it to be within a range. How can i set a range for the input?

Thanks,
ToDi1010
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You probably need come up with the logic to implement this. I can't think of anything in the Java API that will implement this directly. What do you want the program to do if the user enters an "invalid" number? From there you should come up with some sequence of steps to make this happen. At first, don't worry about writing it in Java. Most people find it more natural to explain the steps to take in their native language and then translating that into the programming language they are using.

Also, can you explain a little more about your program so we can assist you further? Mostly I am interested whether this is a console application or a GUI?

So once you've answered these questions, please post some more details about what you have done to try to solve this. I'm sure someone here will be more than happy to help fill in any details you need.

Keep coding!

Layne


Java API Documentation
The Java Tutorial
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, Tony!

Show us yer code, pardner. It'll help folks 'round these parts to nudge you in the right direction.

When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Tony Spedaliere
Greenhorn

Joined: Sep 22, 2004
Posts: 2
package dawson111.labExercises;

import javax.swing.*;

public class TelephoneNumber
{
public static void main(String[] args)
{
//variable declarations
String inputString;
int firstThree > 221; //Beginning of Range
int lastFour < 993; //End of Range

//Accept the required data
inputString =
JOptionPane.showInputDialog("Enter the first three digits:");
firstThree = Integer.parseInt(inputString);
inputString =
JOptionPane.showInputDialog("Enter the last four digits:");
lastFour = Integer.parseInt(inputString);


//Display the output
System.out.println("************** Telephone Number ****************");
System.out.println();
System.out.println("Telephone Number: (514)" + firstThree +"-"+ lastFour);

}//end main method
}//end Average class
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
(Clearing throat...)

Originally posted by Dirk Schreckmann:
When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand.


Note that you can edit your own posts. Just click on the icon that looks like a piece of paper above the post.
[ September 22, 2004: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
It occurs to me that you could be thinking about doing one of a couple different things.

First Scenario: After the user submits data through the dialog box, your program examines the input data. If the data is not of the proper format or not within the correct range, your program then perhaps lets the user know of the mistake, and requests new input. This process would repeat until valid data were input.

Second Scenario: The user is only able to submit proper data to begin with. The input component simply wouldn't let the user input invalid data.

So, which are you wanting to achieve? (Sometimes, I like to pick the easier-to-implement solution.)
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / AWT / SWT / JFace forum...
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
This might be one way (not sure how you wanted lastFour - is 0001 invalid?)

 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Setting a Range
 
Similar Threads
Javascript error in range validation
Generating Random Number
how to read int or any input value entered in console using DataInputStream??
minimum float/double
how to ip scan