Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.util.Scanner; //Scanner for input
  2. //Class name
  3. public class TESTTEST
  4. {
  5. public static void main(String[] args)//main section
  6. {
  7. //varibles
  8. String speed;
  9. double distance;
  10. double time;
  11. //set scanner
  12. Scanner keyboard = new Scanner(System.in);
  13. //ask for the type of speed input
  14. System.out.println("Enter one of the following: air, water, or steel: "
  15. +"Enter the distance the sound wave will travel:");
  16. speed = keyboard.nextLine();
  17. distance = keyboard.nextDouble();
  18. if (speed.equals("air") || speed.equals("water") || speed.equals("steel"))
  19.  
  20. //set switch
  21. switch (speed)
  22. {
  23.  
  24. case "air":
  25. time = distance/1100;
  26. System.out.print(" It will take" + time + " seconds.");
  27. break;
  28. case "water":
  29. time = distance/4900;
  30. System.out.print(" It will take" + time + " seconds.");
  31. break;
  32. case "steel":
  33. time = distance/16400;
  34. System.out.print(" It will take" + time + " seconds.");
  35. break;
  36. default:System.out.print("Sorry, you must enter air,water,or steel.");
  37.  
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement