This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

string return statement  RSS feed

 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If user in jTextField type "7Li", how I can get in output -> "7-Li-3"?
 
Paweł Baczyński
Bartender
Posts: 2054
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
It is a from Periodic table, element Li (lithium) with atomic number 3 and mass 7.
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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 ?
 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Carey Brown
Bartender
Posts: 3027
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you very much Carey Brown.
HashMap solved my problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!