• 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
  • Paul Clapham
  • Tim Cooke
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst
  • Peter Rooke
  • Mikalai Zaikin
Bartenders:
  • Himai Minh

Convert help

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I'm new to java micro developing and I'm making a program that converts units of time,length,temp etc.
My problem is the length of the program because of making if/else of all the possible conversion. For example, converting seconds to minute,hour,weeks,months.
And then converting minute to second,day,hour,weeks. Is there a shortcut for this?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about convering everything to a base unit, and then converting from the base unit to the target unit? E.g. for time: "minutes to days" becomes "minute to second" and then "second to days".
 
Henry Pastor
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ahh. But you select the conversion unit with 2 choicegroup. The first one is for the base unit and then the 2nd is the target. Even if I convert everything first to the base before converting to the target unit, I still need to check the choices made in the 2 choicegroups right? So i still need an if else for each.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but you only need (number of items in 1st group) + (number of items in 2nd group) comparisons, not (number of items in 1st group) * (number of items in 2nd group).
 
Henry Pastor
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please explain how it works? I really cant picture it. I'm trying to code it right now
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic