• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

How do I parse a String?

 
Ranch Hand
Posts: 143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm learning about inheritance and on this problem I first have to create a class where I get/set methods and get user input for the data fields.
I suppose I should know it at this point but I don't know how to get the users name when they input it. I copied the whole code but
the issue is at line 51.

Thanks.

 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the problem?
 
Ranch Hand
Posts: 116
2
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm no Swing expert but I think JOptionPane.ShowInputDialog() returns a String. Your "customerNameString" variable will contain whatever String the user entered. What do you need to parse from the input?

See the Documentation for this component and method.
 
Marshal
Posts: 72059
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is more about option panes in the Java Tutorials.
SW is right: if you enter Ryan Bishop in the option pane it will return Ryan Bishop as a String.
Don't write new String(...). Simply write.
String name = JOptionPane.showInputDialog(...);


Of course there is something else. You are not using the String for anything. I presume that is the next stage?

Why are you using option panes? That is very old‑fashioned programming. Find out about Scanner.
 
Ryan Bishop
Ranch Hand
Posts: 143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies. A little while later I realized I didn't have to parse it.

I'm not sure why I'm using joptionpane but I'm not sure about anything I do with java. The book I'm using just says to get "get user input" but in the chapter shows examples with joptionpane. I'm thinking I may just change it to scanner.

Just out of curiosity, why is it old fashioned? Is scanner more efficient in some way?
 
Greenhorn
Posts: 24
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually JOptionPane can be very useful when getting quick little tidbits from the user. I use it whenever something might be missing on a userform or something like that.



That's a good example to use when using JOptionPane.
 
Campbell Ritchie
Marshal
Posts: 72059
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But that is a different scenario from what we have here.
 
Water proof donuts! Eat them while reading this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic