Results 1 to 5 of 5
- 11-18-2012, 04:00 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 57
- Rep Power
- 0
Re: How to check the value entered in the texbox is numeric or non numeric in java
I can appreciate what you have done for this person here, but I cannot get this to work right, because I am trying to check for a double value, and isDigit seems to not work for double values entered??
I have the following code, which is supposed to calculate annual pay for employees based on a base salary, and an annual commission determined by their sales accomplishments, but I need to add an error condition for if an inappropriate value is entered from the users, and to do this I need to make sure they entered a number and nothing else, as entering anything except for a number will crash the program.... 
Unfortunately, when I try to use isDigit, NetBeans keeps barking at me to create a method for it, and I have included the java.lang library, but it seems that isDigit will not check for a double??Java Code:package annual; import java.util.*; import java.lang.*; public class Annual { public static void main(String[] args) { Scanner percent = new Scanner(System.in); System.out.println("Please enter annual sales:"); double yearly = percent.nextInt(); boolean Tnum = isDigit(yearly); double T = 50000; double Amt; double YrPrcnt = yearly * .05; Amt = T + YrPrcnt; System.out.print("The Annual Payrate for employee is:"); System.out.print(Amt); }}
The line boolean Tnum = isDigit(yearly); is what is upsetting NetBeans here. 
I REALLY need to create an error condition here, but I have no idea how to validate the user input in Java to be honest, so any advice will be greatly appreciated!!
- 11-18-2012, 04:15 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Re: How to check the value entered in the texbox is numeric or non numeric in java
Please don't hijack someone else's thread. I have moved your post to its own thread.
The advice you quote is a bit out of context since I have moved the thread, but it refers to the java API, in particular the Integer (Java Platform SE 6) class, the method being static and this is how you must access it. The API has a wealth if information, for instance if you look at the Scanner method class you will see many different methods for reading input - if you need a double you can use the appropriate method of this class, or read a String and parse it using the appropriate method in the Double class (again, see the API)
- 11-18-2012, 12:44 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 57
- Rep Power
- 0
Re: How to check the value entered in the texbox is numeric or non numeric in java
My apologies, I just was interested in the idea of isDigit(). but it seems to not exist, or be of any true help....

Also, I am not clear on this, " The API has a wealth if information", where would I find this API again??
I apologize, but although I have some background with Java, this is kind of my first experience with NetBeans, so I am not really well versed on the application to be honest..gif)
Thanks for letting me know that isDigit() is outdated, I will try to figure out Try & Catch a little better, and maybe go a different route with my validation concept, and again, thanks for taking a look at my post here anyway!!
-
Re: How to check the value entered in the texbox is numeric or non numeric in java
He's given you a link to the API in his reply. As to why NetBeans is "barking", it's not NetBeans, its Java that's complaining because you're calling a method that doesn't exist pure and simple, and this has nothing to do with something being "out dated", it's just that you're calling the method as if you've created a static method with this name, but you haven't. But regardless of that, a method of this type at this location being called on a double variable is really meaningless. What are you trying to do with this any way?
- 11-18-2012, 10:43 PM #5
Member
- Join Date
- Nov 2012
- Posts
- 57
- Rep Power
- 0
Re: How to check the value entered in the texbox is numeric or non numeric in java
I am trying to validate user input at a prompt, because my program relies on them entering a numeric double value, and if they enter anything except a number it crashes.
As to me calling a method that doesn't exist, I was trying to follow the instructions provided here to use isDIgit(), which I was led to believe was a pre-designed function provided by the java.lang library.gif)
If that is incorrect, then I must have mistaken what I read on this forum concerning isDigit(), and would like any suggestions about how to verify that the users only input a number, Please!!
Similar Threads
-
How to check the value entered in the texbox is numeric or non numeric in java
By newbie_tiwari in forum New To JavaReplies: 7Last Post: 11-18-2012, 04:22 AM -
Numeric priorities - which seems more intuitive to you?
By kjkrum in forum Forum LobbyReplies: 0Last Post: 03-19-2012, 05:09 PM -
How to test whether the entered value is numeric or it contains some characters.
By radhi16 in forum New To JavaReplies: 3Last Post: 01-19-2011, 06:25 PM -
How to test whether the entered value is numeric or it contains some characters.
By renu in forum New To JavaReplies: 13Last Post: 09-23-2010, 07:21 PM -
How do check I allow user to enter only alpha numeric and -?
By tanalyw in forum New To JavaReplies: 2Last Post: 04-16-2008, 12:18 PM


LinkBack URL
About LinkBacks
Reply With Quote.gif)

Bookmarks