posted 12 years ago

Hello Pple..

Hmm.. anyone knows of a simple yet efficient ways to

calculate resistance values of a resistor with 3 color bands??

Means user enter 3 color into textfield:

eg: red, orange, grey.

so the program will calculate total value entered by user.

The value for red - 2, orange - 3, brown - 1.

i know i need to use the method pow() for multiplier.

But i'm not very sure what to be types inside..

Thanks for your attention!!

Hmm.. anyone knows of a simple yet efficient ways to

calculate resistance values of a resistor with 3 color bands??

Means user enter 3 color into textfield:

eg: red, orange, grey.

so the program will calculate total value entered by user.

The value for red - 2, orange - 3, brown - 1.

i know i need to use the method pow() for multiplier.

But i'm not very sure what to be types inside..

Thanks for your attention!!

posted 12 years ago

Take a look at the Java 5.0

**enum**construct. It could be the ideal thing for solving your problem.Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch

Getting someone to think and try something out is much more useful than just telling them the answer.

posted 12 years ago

You could use the Math.pow() method for this, but that's seems to complicate the issue, in my opinion. Because then you have to get around the messiness of getting numeric values you could multiply by the value returned by Math.pow().

You could create a method that converts the color band Strings into integers (i.e. "red" returns 2). You could put those returned values into a StringBuffer. For the multiplier band, you could add zeros to the StringBuffer based on the integer value (i.e. for 5 add five zeros).

Convert the StringBuffer to a String and you are done.

Certainly not the only way you could do it, but the simplest I can think of this late at night.

Originally posted by may tan:

i know i need to use the method pow() for multiplier.

But i'm not very sure what to be types inside..

You could use the Math.pow() method for this, but that's seems to complicate the issue, in my opinion. Because then you have to get around the messiness of getting numeric values you could multiply by the value returned by Math.pow().

You could create a method that converts the color band Strings into integers (i.e. "red" returns 2). You could put those returned values into a StringBuffer. For the multiplier band, you could add zeros to the StringBuffer based on the integer value (i.e. for 5 add five zeros).

Convert the StringBuffer to a String and you are done.

Certainly not the only way you could do it, but the simplest I can think of this late at night.

Wannabe SCJP 1.4<br /> <br />It wasn't raining when Noah built the ark.<br /> --Howard Ruff