Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package act;
- import java.util.Scanner;
- public class SpeedOfSound
- {
- public static void main(String[] args)
- {
- Scanner keyboard = new Scanner(System.in);
- Double x;
- System.out.println("The following table shows the approximate speed of sound in air, water, and steel:\r\n" +
- "\r\n" +
- "Medium Speed\r\n" +
- "---------------------------------------\r\n" +
- "Air 1,100 feet per second\r\n" +
- "Water 4,900 feet per second\r\n" +
- "Steel 16,400 feet per second");
- System.out.print("Enter the medium in which you would like to travel:");
- String med = keyboard.nextLine();
- med = med.toUpperCase();
- System.out.print("Enter the distance you would like to travel (in feet):");
- int dis = keyboard.nextInt();
- switch(med)
- {
- case "AIR":
- x = 1100.00;
- break;
- case "WATER":
- x = 4900.00;
- break;
- case "STEEL":
- x = 16400.00;
- break;
- default:
- System.out.println("invalid medium");
- x = 0.00;
- }
- double t = dis/x;
- System.out.println("It will take sound "+t+" seconds to travel "+dis+
- " feet of "+med+".");
- keyboard.close();
- }
- }
Add Comment
Please, Sign In to add comment