This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to calculate resistance values of a resistor with 3 colour bands? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to calculate resistance values of a resistor with 3 colour bands?" Watch "How to calculate resistance values of a resistor with 3 colour bands?" New topic
Author

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

may tan
Greenhorn

Joined: Jul 22, 2005
Posts: 22
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

Joined: Aug 03, 2002
Posts: 7729
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.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Moving to Java in General (Beginner).


[Jess in Action][AskingGoodQuestions]
Patrick Haley
Greenhorn

Joined: Sep 15, 2004
Posts: 10
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to calculate resistance values of a resistor with 3 colour bands?
 
Similar Threads
getContextPath()
Calling a Hashtable from another class.
How to take dynamic values of textboxes to Action class
How to use method pow()? [based on resistance value question]
How to fill in color?