In the Resistor class from Exercise P8.20, supply a method that returns a description of the color

Question:

In the Resistor class from Exercise P8.20, supply a method that returns a description of the “color bands” for the resistance and tolerance. A resistor has four color bands: 

• The first band is the first significant digit of the resistance value.
• The second band is the second significant digit of the resistance value.
• The third band is the decimal multiplier.
• The fourth band indicates the tolerance.

For example (using the values from the table as a key), a resistor with red, violet, green, and gold bands (left to right) will have 2 as the first digit, 7 as the second digit, a multiplier of 105, and a tolerance of ±5 percent, for a resistance of 2,700 kΩ, plus or minus 5 percent.


Data from Exercise P8.20

The colored bands on the top-most resistor shown in the photo below indicate a resistance of 6.2 kΩ ±5 percent. The resistor tolerance of ±5 percent indicates the acceptable variation in the resistance. A 6.2 kΩ ±5 percent resistor could have a resistance as small as 5.89 kΩ or as large as 6.51 kΩ. We say that 6.2 kΩ is the nominal value of the resistance and that the actual value of the resistance can be any value between 5.89 kΩ and 6.51 kΩ.

Write a program that represents a resistor as a class. Provide a single constructor that accepts values for the nominal resistance and tolerance and then determines the actual value randomly. The class should provide public methods to get the nominal resistance, tolerance, and the actual resistance. Write a main method for the program that demonstrates that the class works properly by displaying actual resistances for ten 330 Ω ±10 percent resistors.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Java Concepts Late Objects

ISBN: 9781119186717

3rd Edition

Authors: Cay S. Horstmann

Question Posted: