Resistors are electric components that limit or regulate the flow of electrical
current in an electronic circuit. Resistance, the most important characteristic
of a resistor, is encoded with 4 color stripes using a color-coding scheme
described below.
Implement a class ResistorColors that contains a method resLimits. Given the
colors of the four stripes on a resistor, resLimits calculates the lowest and
the highest values of the encoded resistance.
DEFINITION
Class name: ResistorColors
Method name: resLimits
Parameters: String
Return type: int[]
Method signature: int[] resLimits(String code) (make sure your method is public)
code is a 15-character String containing four three-character color codes
separated by spaces (one space between each three-character group). The first
two colors encode the two significant digits of the resistance; the third color
encodes the multiplication factor; the forth color encodes resistor's accuracy.
Use table below to interpret the meaning of the first three stripes.
| | first | second | third
code | color | stripe| stripe | stripe
-----+--------+-------+--------+---------
BLK | black | 0 | 0 | *1
BRW | brown | 10 | 1 | *10
RED | red | 20 | 2 | *100
ORN | orange | 30 | 3 | *1000
YLW | yellow | 40 | 4 | *10000
GRN | green | 50 | 5 | *100000
BLU | blue | 60 | 6 | *1000000
PUR | purple | 70 | 7 | not used
GRY | gray | 80 | 8 | not used
WHT | white | 90 | 9 | not used
For example, if the first three stripes are BRW BLK ORN, they encode the value
of (10+0)*1000=10000.
The fourth stripe is either gold (GLD) or silver (SLV). Resistors with a gold
stripe have 5% accuracy; resistors with a silver stripe have 10% accuracy.
Your method should return a int[] with two values. The first value represents
the lowest resistance, and the second value represents the highest resistance
that may correspond to the given color code. Values must be rounded to the
nearest whole resistance value. If the value is .5 or greater, round up (i.e.
1.5 would be rounded up to 2). For example, "BRW BLK ORN GLD" is a 10000-Ohm
resistor with 5% accuracy; your method should return {9500,10500}.
NOTES
The return int[] must contain the lowest resistance value as the first element
and the highest resistance value as the second element.
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following criteria are met:
- code will contain four three-character groups separated by spaces (one space
between each three-character group).
- all characters will be in upper case.
- code will represent a valid resistance and accuracy, as described above.
EXAMPLES
- If code="WHT BLK BLU SLV", return {81000000, 99000000}
- If code="WHT BLK BLU GLD", return {85500000, 94500000}
- If code="YLW BRW BLU SLV", return {36900000, 45100000}
- If code="BLK RED BLK SLV", return {2,2}
- If code="BLU RED BLU GLD", return {58900000, 65100000}
- If code="PUR GRY GRN SLV", return {7020000, 8580000}
- If code="ORN GRY RED GLD", return {3610, 3990}