-1

I want to print corresponding string values, to find the inductance or an inductor using the colour codes in java

public class Inductance
{
 
  // Function to find the inductance
  // using color codes of inductor
  public static void findInductance(String a, String b, String c, String d)
  {
 
    // Hash-map to store the values
    // of the color-digits
    HashMap<String, String> color_digit = new HashMap<String, String>() ;
    color_digit.put("black", "0");
    color_digit.put("brown", "1");
    color_digit.put("red", "2");
    color_digit.put("orange", "3");
    color_digit.put("yellow", "4");
    color_digit.put("green", "5");
    color_digit.put("blue", "6");
    color_digit.put("violet", "7");
    color_digit.put("grey", "8");
    color_digit.put("white", "9");
 

    if (color_digit.containsKey(a)
        && color_digit.containsKey(b)
        && multiplier.containsKey(c)
        && tolerance.containsKey(d))
    {
      String xx = color_digit.get(a);
      String yy = color_digit.get(b);
      String zz = multiplier.get(c);
      String aa = tolerance.get(d);
      System.out.println("Inductance = " + xx + yy+
                         " x " + zz + " ohms " +  aa);
    }
    else
      System.out.println("Invalid Colors");
  }
 
  // Driver Code
  public static void main(String[] args)
  {
    String a = "black";
    String b = "brown";
    String c = "red";
    String d = "green";
 
    // Function Call
    findInductance(a, b, c, d);
  }
}

For example, the colour bands are black, brown and red, The inductance should be 102, and so on (Ps. I have added Multiplier and Tolerance hashmaps too, but the site says the code is too long, sooo)

  • What is the exact error message you are getting. And what is `multiplier` and `tolerance` supposed to be in the code above?You seem to use those variables as maps but they are never defined anywhere. – OH GOD SPIDERS Dec 16 '22 at 10:00

2 Answers2

1

Try importing it:

 import java.util.HashMap;
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
0

you could check the imports and try to do

Map<String, String> color_digits = new HashMap<String, String>();

else i dont see anything strange

Krypt0n112
  • 11
  • 4