pico, nano, micro and Java  
Author Message
Paul in Toronto





PostPosted: 2006-4-14 9:04:00 Top

java-programmer, pico, nano, micro and Java First off, this is for a school assignment... I know some people get
squeamish about this sort of post, but I'm kind of up a creek.

Basically, as part of a semester-long project, we need to add another bean
to a program we've been working on, and integrate it with the rest of the
program. That part's not the issue.

Part of the specification for the bean states tnat the user must be able to
select (and optionally enter) values ranging from 100 picofarads up to 1
microfarad. That's 1 * 10^-10 up to 1 * 10^-6, and everything in between.
Now... For ease of use purposes, the input is supposed to involve something
like a combobox or a spinner or a slider, or something like that, with
clearly delineated default values, which the user can then customise.

So, for testing purposes, I have a combobox containing the numbers 1 to 10,
and a second combobox that allows you to select your unit (pF, nF, uF).

So... In an attempt to get this post over with... Does Java include a
quick and easy way of taking an entry like "250 nF" and converting it to
2.5*10^-7 for calculation purposes? I was thinking of putting the whole
thing into a switch based on the contents of the units box (or possibly a
bunch of if statements), but then there's the problem of a certain amount of
variation in the multipliers used depending on the actual number entered.

Does any of this make sense?


 
IchBin





PostPosted: 2006-4-14 10:23:00 Top

java-programmer >> pico, nano, micro and Java Paul in Toronto wrote:
> First off, this is for a school assignment... I know some people get
> squeamish about this sort of post, but I'm kind of up a creek.
>
> Basically, as part of a semester-long project, we need to add another bean
> to a program we've been working on, and integrate it with the rest of the
> program. That part's not the issue.
>
> Part of the specification for the bean states tnat the user must be able to
> select (and optionally enter) values ranging from 100 picofarads up to 1
> microfarad. That's 1 * 10^-10 up to 1 * 10^-6, and everything in between.
> Now... For ease of use purposes, the input is supposed to involve something
> like a combobox or a spinner or a slider, or something like that, with
> clearly delineated default values, which the user can then customise.
>
> So, for testing purposes, I have a combobox containing the numbers 1 to 10,
> and a second combobox that allows you to select your unit (pF, nF, uF).
>
> So... In an attempt to get this post over with... Does Java include a
> quick and easy way of taking an entry like "250 nF" and converting it to
> 2.5*10^-7 for calculation purposes? I was thinking of putting the whole
> thing into a switch based on the contents of the units box (or possibly a
> bunch of if statements), but then there's the problem of a certain amount of
> variation in the multipliers used depending on the actual number entered.
>
> Does any of this make sense?
>
>
Think you want to look at the java.math.BigDecimal and
java.lang.Math.pow(double x, double p) classes. You need to check the
API for more info.

For pow(double x, double p) It returns the value of the first argument
raised to the power of the second argument.


--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
Oliver Wong





PostPosted: 2006-4-14 23:35:00 Top

java-programmer >> pico, nano, micro and Java "Paul in Toronto" <email***@***.com> wrote in message
news:gyC%f.4548$email***@***.com...
>
> Part of the specification for the bean states tnat the user must be able
> to select (and optionally enter) values ranging from 100 picofarads up to
> 1 microfarad. That's 1 * 10^-10 up to 1 * 10^-6, and everything in
> between. Now... For ease of use purposes, the input is supposed to
> involve something like a combobox or a spinner or a slider, or something
> like that, with clearly delineated default values, which the user can then
> customise.
>
> So, for testing purposes, I have a combobox containing the numbers 1 to
> 10, and a second combobox that allows you to select your unit (pF, nF,
> uF).
>
> So... In an attempt to get this post over with... Does Java include a
> quick and easy way of taking an entry like "250 nF" and converting it to
> 2.5*10^-7 for calculation purposes? I was thinking of putting the whole
> thing into a switch based on the contents of the units box (or possibly a
> bunch of if statements), but then there's the problem of a certain amount
> of variation in the multipliers used depending on the actual number
> entered.
>
> Does any of this make sense?

Rather than 2 combo boxes, you should probably go with 1 combo box and 1
slider, or one text box and one combo box. That is, have one control to set
the number (e.g. "250"), and another control to set the units (e.g. "nano").

Then, whenever you have nano, multiply the figure in the first control
by 10^-9. With Micro, do 10^-6, etc. Assuming you support only "pico",
"nano" and "micro", that means 3 cases in your switch statement.

So if the user enters "250 nF", you take 250, multiply it by 10^-9, and
get an in memory value whose string representation may be any of "250 *
10^-9", "25 * 10^-8", "2.5 * 10^-7", or something else.

- Oliver