Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. /*
  2. Yvvy Chen
  3. AP CSA F Block
  4. Peg Leg
  5. September 10
  6. Temperature Converter
  7. */
  8.  
  9. import java.util.Scanner;
  10.  
  11. public class TempConverter {
  12.  
  13. public static void main(String[] args) {
  14. // TODO Auto-generated method stub
  15.  
  16. Scanner sc = new Scanner(System.in);
  17.  
  18. //doubles for degree temperatures
  19. double F;
  20. double C;
  21.  
  22. //beginning of loop for if they want to try another number
  23. String again = "yes";
  24. while (again.equals("yes") || again.equals("y")) {
  25.  
  26. //menu because Peg Leg likes it
  27. System.out.println("Welcome to Temperature Converter\n");
  28. System.out.println("In which direction would you like to convert?");
  29. System.out.println("1) Fahrenheit to Celcius");
  30. System.out.println("2) Celcius to Fahrenheit\n");
  31.  
  32. int direction = sc.nextInt();
  33.  
  34. //F to C
  35. if (direction == 1) {
  36. System.out.println("What degree Fahrenheit would you like to convert?");
  37. F = sc.nextInt();
  38. C = (F-32) * 5/9.0;
  39. System.out.println("\n" + F + " degrees in Fahrenheit is equal to " + C + " degrees Celcius");
  40. }
  41.  
  42. //C to F
  43. if (direction == 2) {
  44. System.out.println("What degree Celcius would you like to convert?");
  45. C = sc.nextInt();
  46. F = (9.0/5) * C + 32;
  47. System.out.println("\n" + C + " degrees in Celcius is equal to " + F + " degrees Fahrenheit");
  48. }
  49.  
  50. //Ask if they want to try a different number
  51. System.out.println("\nWould you like to convert a different number? (Enter either \"yes\" or \"no\").");
  52. sc.nextLine();
  53. again = sc.nextLine();
  54. }
  55.  
  56. //calling them a loser if no
  57. if (again.equals("no") || again.equals("n")) {
  58. System.out.println("Loser");
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement