• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string return statement

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If user in jTextField type "7Li", how I can get in output -> "7-Li-3"?
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the rules of the conversion?
Where did the "3" come from?
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a from Periodic table, element Li (lithium) with atomic number 3 and mass 7.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tai Yo wrote:It is a from Periodic table, element Li (lithium) with atomic number 3 and mass 7.



Well, first, you will need access to the periodic table -- either directly defined in your program, loaded from somewhere such as a file or database, or access via some sort of service.

With that, all you need is to define the parsing rules (consistency of format), so you can parse it, find the element, lookup the atomic number and mass, and generate the result.

Henry
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I should avoid periodic table loaded from file or database.
Is there another way to solve it, for example, mapping or ?
 
Sheriff
Posts: 7125
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

Tai Yo wrote:I should avoid periodic table loaded from file or database.


Sounds like an assignment.

Is there another way to solve it, for example, mapping or ?


You could type in a map of the whole periodic table, but that would be a pain. If this is an assignment, do they really want you to do all that busy work? If not, loading a map from a file would be an intermediate step, and a database like SQLite would be the best solution.
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tai Yo wrote:If user in jTextField type "7Li", how I can get in output -> "7-Li-3"?


You could do it with a Map.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Carey Brown.
HashMap solved my problem.
 
reply
    Bookmark Topic Watch Topic
  • New Topic