Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to calculate resistance values of a resistor with 3 colour bands?

 
may tan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the Java 5.0 enum construct. It could be the ideal thing for solving your problem.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java in General (Beginner).
 
Patrick Haley
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic