12,( Bar Chart use Netbeans ) complete the problem exactly as described The spee
ID: 3540399 • Letter: 1
Question
12,( Bar Chart use Netbeans ) complete the problem exactly as described
The speed of sound
The following table shows the approximate speed of sound in air,water,and steel:
Medium Speed
-----------------------------------------------
Air 1,100 feet per second
Water 4,900 feet per second
Steel 16,400 feet per second
Write a program that asks the user to enter "air","water",or "stell", and the distance that a sound wave will travel in the meduim.The program should then display the amount of time it will take .Youcan calculate the amount of time it takes sound to travel in air with the following formula:
Time = Distance/1,100
You can calculate the amount of time it takes sound to travel in water with the following formula:
Time = Distance/4,900
You can calculate the amount of time it takes sound to travel in steel with the following formula:
Time = Distance/16,400
Explanation / Answer
import java.util.*;
public class example {
public static void main(String[] args) {
example e = new example();
Scanner s = new Scanner(System.in);
String flag = "y";
System.out.println("enter the medium and distance...respectively");
String medium = s.next();
double time=0;
double distance = s.nextDouble();
if(medium.equalsIgnoreCase("air")){
time = distance/1100;
}else if(medium.equalsIgnoreCase("steel")){
time = distance/16400;
}else if(medium.equalsIgnoreCase("water")){
time = distance/4900;
}else{
System.out.println("enter correct medium");
}
if(time!=0)
System.out.println("Time : "+time);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.