#274 Write an interactive Java program, ColorRange.java
Write an interactive Java program, ColorRange.java - Computer Science
ChemistryExplain daily providing Q&A content “#274 Write an interactive Java program, ColorRange.java" in Computer science, Ba computer science, Berkeley computer science, Computer science associate degree jobs
Get the Free Online Chemistry Q&A Questions And Answers with explain. To crack any examinations and Interview tests these Chemistry Questions And Answers are very useful. Here we have uploaded the Free Online Chemistry Questions. Here we are also given the all chemistry topic.
ChemistryExplain team has covered all Topics related to inorganic, organic, physical chemistry, and others So, Prepare these Chemistry Questions and Answers with Explanation Pdf.
For More Chegg Questions
Free Chegg Question
Write an interactive Java program, ColorRange.java, which when given a wavelength in nanometers will return the corresponding color in the visible spectrum.
You must implement the following using a suitable if decision statement.
1. Prompt the user to enter the wavelength, the wavelength should be of type double.
2. For each range (e.g. 380-450) the number on the left is included in the range, but the number on the right is not included in the range.
3. If the input value is not found on the visible spectrum then state that the wavelength is not within the visible spectrum.
4. Expected Output:
a. Enter a color code 630 The color is Red
b. Enter a color code 25.0 The entered wavelength is not a part of the visible spectrum
C. Enter a color code 750.5 The entered wavelength is not a part of the visible spectrum
For More Chemistry Notes and Helpful Content Subscribe Our YouTube Chanel - Chemistry Explain
Free Chegg Answer
ColorRange.java
import java.util.Scanner;
public class ColorRange {
public static void main(String[] args) {
//Set scanner to get user input
Scanner sc = new Scanner(System.in);
//Ask user to enter wavelwength
System.out.println("Enter a color code:");
//Assign value to colorcode variable
double colorcode = sc.nextDouble();
//Put a msg 'Color is' and the concatenate with color
String msg = "Color is ";
if(colorcode>=380 && colorcode<450)
//here we used shorthand += operator to concatenate string
// OR you can use a simple method like msg = msg + "Violet"; also
msg += "Violet";
else if(colorcode>=450 && colorcode<495)
msg += "Blue";
else if(colorcode>=495 && colorcode<570)
msg += "Green";
else if(colorcode>=570 && colorcode<590)
msg += "Yellow";
else if(colorcode>=590 && colorcode<620)
msg += "Orange";
else if(colorcode>=620 && colorcode<750)
msg += "Red";
else
// If no conditions meet criteria then show this msg
msg = "The entered wavelength is not a part of the visible spectrum";
//print message
System.out.println(msg);
}
}
Labels: Chegg, Free Chegg Answer, Q&A Computer Science
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home