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

Write a Java program that completes the following problem by using if/else if st

ID: 3671859 • Letter: W

Question

Write a Java program that completes the following problem by using if/else if statements

Problem:

One of the common problems encountered in computing is the point location problem, where the goal is to identify the range in which a given point falls. In this program, our “point” is a wavelength (in nanometers), specified as a float value, and the ranges are the seven colors of the visible spectrum. The input to the program is thus a real value that lies between 400.0 and 700.0. The color conversions are:

We shall assume for now that the input always falls within this range (the user of the program must take on the responsibility of ensuring that the input is correct, i.e., the program is not expected to give meaningful answers for input outside this range). The entire range of input values can be represented by the following structure:

400 . . .445 . . . 475 . . . 510 . . . 570 . . . 590 . . . 650 . . . 700

The lowest possible input value is 400.0 and the highest possible value is 700.0 Each of the in-between numbers (such as 445, 475) serves as a “divider”; put together, they partition the entire range into 7 sub-ranges.

We can write a conditional statement to achieve this partition. Note that at each step we are comparing the input with one of the “dividers”, thus narrowing the range within we much we must continue the search.

Strategy.

Our strategy is as follows: Compare the input number with the first divider

(445). If the number is smaller than the divider, we print the answer “Violet”; if not we continue with the next divider.

Output Should look like the following:

run: Please input a wavelength between 400.0 and 700.0: 701Please input a wavelength between 400.0 and 700.0: 600 Your input is out of range! Thank you for using our program BUILD SUCCESSFUL total time: 4 seconds Your wavelength correeponda to the color is: Orange. Thank you for using our program! BOTLD SUCCESSFUL (total time: 5 aconds)

Explanation / Answer

import java.util.*;
public class SevenCol {
  
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("please input a wavelength between 400.0 to 700.0");
float w=0.0f;
w=s.nextFloat();
if(w>=400.0f && w<=445.0f)
System.out.println("Your walength correspo0nds to the color is:Violet");
if(w>445.0f && w<=475.0f)
System.out.println("Your walength correspo0nds to the color is:Indigo");
if(w>475.0f && w<=510.0f)
System.out.println("Your walength correspo0nds to the color is:Blue");
if(w>510.0f && w<=570.0f)
System.out.println("Your walength correspo0nds to the color is:Green");
if(w>570.0f && w<=590.0f)
System.out.println("Your walength correspo0nds to the color is:Yellow");
if(w>590.0f && w<=650.0f)
System.out.println("Your walength correspo0nds to the color is:Orange");
if(w>=650.0f && w<=700.0f)
System.out.println("Your walength correspo0nds to the color is:Red");
if(w<400 || w>700)
System.out.println("invalid input");
System.out.println("Thank You");
  
}
  
}

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