You can calculate the amount of time it takes sound to travel in air with the following formula:

Time = Distance / 1100

You can calculate the amount of time it takes sound to travel in water with the following formula:

Time = Distance / 4900

You can calculate the amount of time it takes sound to travel in steel with the following formula:

Time = Distance / 16400

The problem is that I am having a lot of problems creating this. I thought I would do it by utilizing switch commands but I am still a noob. I am getting some error messages. Here is the code:

/* code import java.util.Scanner; /* PROGRAM: TheSpeedofSound.java Written by Julio C. Villa The following table shows the approximate speed of sound in air, water, and steel: Medium Speed Air 1100 feet per second Water 4900 feet per second Steel 16,400 feet per second Write a program that asks the user to enter "air", "water", or "steel", and the distance that a sound wave will travel in the medium. The program should then display the amount of time it will take. You can calculate the amount of time it takes sound to travel in air with the following formula: Time = Distance / 1100 You can calculate the amount of time it takes sound to travel in water with the following formula: Time = Distance / 4900 You can calculate the amount of time it takes sound to travel in steel with the following formula: Time = Distance / 16400 */ public class TheSpeedofSound { public static void main(String[ ] args) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter air, water, or steel: "); String air; String water; String steel; air = keyboard.nextLine(); water = keyboard.nextLine(); steel = keyboard.nextLine(); System.out.print("Enter distance: "); int distance; distance = keyboard.nextInt(); switch (air || water || steel) { case air: int time; time = (distance / 1100) System.out.println("The total time traveled is " + time + "."); case water: time = (distance / 4900) System.out.println("The total time traveled is " + time + "."); case steel: time = (distance / 16400) System.out.println("The total time traveled is " + time + "."); } } }

Any help in this will be appreciated. Thank you!

Jay

This post has been edited by **macosxnerd101**: 06 April 2011 - 06:32 PM

Reason for edit:: A little late, but added code tags.