Results 1 to 2 of 2
Thread: int and String, help me
- 07-24-2007, 04:25 AM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
int and String, help me
Hi, I'm making this class to take a customer's order for a project, but I hit a snag. Basically I'm asking a customer for the amount of pizzas they want, then the size, the first topping, and the last topping.
The amount of pizzas they want will initiate the amount of times my "for loop" will run to ask the same round of questions.
for the size of the pizzas, I've assigned (1)small (2)medium (3)large. The customer enters the respective number, and i take the input as
I'll get a int number between 1-3, but now how do i assign a string value to an integer?Java Code:int size=JOptionpane.showInputDialog("Whats the size?(1)small(2)medium(3)large" )
like how do i get the input of "1" to mean "small"?
Thanks
- 07-24-2007, 12:14 PM #2
Member
- Join Date
- Jul 2007
- Location
- England, Bath
- Posts
- 47
- Rep Power
- 0
Step 1 is quite straight forward. You can use the parseInt function on the Integer class:
Remember to check for NumberFormatExceptions if the user types in rubbish.Java Code:int number = Integer.parseInt(someString);
The next bit of making the 1 mean small can be as simple as defining a constant in your class but you may want to investigate using an enum instead.
Hope this helps.
Similar Threads
-
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
String vs new String
By bugger in forum New To JavaReplies: 20Last Post: 11-26-2007, 12:21 PM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM -
Help with insertName(String name) and deleteName(String name)
By trill in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:29 AM -
I can't seem to pass the value of a string variable into a string array
By mathias in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks