476179

speedofSoundSwitch

Nov 4th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. package act;
  2. import java.util.Scanner;
  3.  
  4. public class SpeedOfSound
  5. {
  6.  
  7. public static void main(String[] args)
  8. {
  9. Scanner keyboard = new Scanner(System.in);
  10. Double x;
  11. System.out.println("The following table shows the approximate speed of sound in air, water, and steel:\r\n" +
  12. "\r\n" +
  13. "Medium Speed\r\n" +
  14. "---------------------------------------\r\n" +
  15. "Air 1,100 feet per second\r\n" +
  16. "Water 4,900 feet per second\r\n" +
  17. "Steel 16,400 feet per second");
  18. System.out.print("Enter the medium in which you would like to travel:");
  19. String med = keyboard.nextLine();
  20. med = med.toUpperCase();
  21. System.out.print("Enter the distance you would like to travel (in feet):");
  22. int dis = keyboard.nextInt();
  23.  
  24. switch(med)
  25. {
  26. case "AIR":
  27. x = 1100.00;
  28. break;
  29. case "WATER":
  30. x = 4900.00;
  31. break;
  32. case "STEEL":
  33. x = 16400.00;
  34. break;
  35. default:
  36. System.out.println("invalid medium");
  37. x = 0.00;
  38. }
  39.  
  40. double t = dis/x;
  41. System.out.println("It will take sound "+t+" seconds to travel "+dis+
  42. " feet of "+med+".");
  43.  
  44.  
  45.  
  46.  
  47.  
  48. keyboard.close();
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55. }
Add Comment
Please, Sign In to add comment