Good evening! Could someone help me with the code for the problem below? It is an exercise suggested by a professor of an engineering course. Below is the requested, if anyone can help, I would be very grateful.
"In previous exercises, we created an algorithm to convert a resistor color code into a numerical resistance value. Now, we'll do the reverse. Make a program that, when entering the resistance value, returns the resistor color code.
Note: Just consider resistance values from 10 Ω. In other words, just consider the colors black, brown, red, orange, yellow, green, blue, violet, gray and white. No need to consider resistors larger than 91 MΩ. In other words, it will eventually not be necessary to use the unsigned int or long int data types to store the resistor values, as the values will not be very large numerically.
Part 1 ----> After the welcome messages and information, including the name of the author of the program, the user must enter the keyboard with an integer value between 10 and 91000000. The program can only advance if the user types one integer in this range of values.
Note: There is no need to test if the user typed an integer.
Complement: when pressing enter, ‘Ω’ must be printed after the entered number.
Part 2 ----> The computer must identify the first two digits and inform if the resistor is part of the E-24 series. (10, 11, 12, 13, 15, 16, 18, 20, 22, 24, 27, 30, 33, 36, 39, 43, 47, 51, 56, 62, 68, 75, 82, 91)
Note: Remember to make simple and short solutions.
Complement: if not part of E-24, ask again for resistor.
Part 3 ----> Must have a method that takes a number, between 0 and 9, and returns a string with the name of the color. This method should be used to get the 3 colors.
Part 4 ----> The 3 colors returned must be stored in a string vector. Print the three colors on the screen.
Complement: The method call developed in (3) must be inside a repeating loop.
Part 5 ----> Ask user for resistor power. Return to the user the maximum voltage that that resistor can be subjected to ( 𝑉=√𝑃.𝑅 ). The calculation must be done within a new method.
--- Update ---
Here's what I managed to do:
import java.util.Scanner; class Main { public static void main(String[] args) { System.out.println("Hello, welcome! This program takes the resistance value and returns the resistor color according to the color code."); System.out.println("Author: Geralt96"); Keyboard Scanner = new Scanner(System.in); System.out.println("Enter resistor value"); int res = (keyboard.nextInt()); while (res < 10 | | res > 91000000) { System.out.println("Number out of range"); System.out.println("Enter resistor value"); res = (keyboard.nextInt()); } System.out.println(res+"Ω"); } }