Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How write a program that will determine the resistance value (in Ohms or kOhms)o

ID: 3690772 • Letter: H

Question

How write a program that will determine the resistance value (in Ohms or kOhms)of a carbon or metal film resistor (ranging from 1/8 to 5 watts) when the program user inputs the three colors of the resistors color band. Your program should accept the following charactes as string variable inputs for the three resistor color bands. Black = 'B' Brown='b' RED='R' or 'r' orange ='O' or 'o'follows pattern above Yellow= Y or y(4 for bands one or two and pow(10,4) for band three Green 'G'(5 for bands one or two and pow(10,5) for band three blue='U' (6 for bands one or two and pow(10,6) for band three Violet = 'V' (7 for bands one and two and not used in band three because color cod only include resistors less than 100 Mohms) Gray='g' (8 for bands one and two and not included in band three) White='W' or 'w' (9 for bands one or two and not used in band three) I'm trying to used switch case or else/if to solve this problem. black =pow(10,0) brown=pow(10,1) red=pow(10,2) the pattern continues all the way to white by increasing it by one. for example if the user entered 'O' and 'r' and 'b' then the corresponding resistor value to print out would be 32* pow (10,0) or 32 ohms. if the user entered 'b','y' and 'G' then the corresponding resistor value would be 14 * pow (10,5) or 1400000

Explanation / Answer

package color.band;

import java.util.HashMap;

import java.util.Scanner;

class ColoValue {

  

HashMap<Character, Integer> color_value;

public ColoValue(){

color_value = new HashMap<Character, Integer>();

   color_value.put('B', 0);

color_value.put('b', 1);

color_value.put('R', 2);

color_value.put('r', 2);

color_value.put('O', 3);

color_value.put('o', 3);

color_value.put('Y', 4);

color_value.put('y', 4);

color_value.put('G', 5);

color_value.put('g', 5);

color_value.put('U', 6);

color_value.put('u', 6);

}

  }

public class ColorBand {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

Scanner sc=new Scanner(System.in);

System.out.println("Enter color band=");;

String str;

while(true) {

str=sc.next();

if(str.length()==4||str.length()==5)

break;

System.out.println("Band must be of 4 or 5 colors");

}

ColoValue obj=new ColoValue();

int resistance=0;

for(int i=0;i<str.length();i++) {

resistance=resistance+(int)Math.pow(10, obj.color_value.get(str.charAt(i)));

}

System.out.println(resistance+"ohm");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote