File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes Convert help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Convert help" Watch "Convert help" New topic
Author

Convert help

Henry Pastor
Greenhorn

Joined: Aug 20, 2012
Posts: 6
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?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42371
    
  64
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".


Ping & DNS - my free Android networking tools app
Henry Pastor
Greenhorn

Joined: Aug 20, 2012
Posts: 6
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
Marshal

Joined: Mar 22, 2005
Posts: 42371
    
  64
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

Joined: Aug 20, 2012
Posts: 6
Can you please explain how it works? I really cant picture it. I'm trying to code it right now
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert help