Advertisement
Guest User

Temparatureconvatar\

a guest
Feb 17th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1.  
  2. package temparaturedemo;
  3.  
  4. import java.util.Scanner;
  5.  
  6. import javax.swing.*;
  7.  
  8. public class TemparatureDemo {
  9.  
  10. public static void main(String[] args) {
  11. double celsius = 0, fahrenheit=0, kalvin=0;
  12. Scanner sc = new Scanner(System.in);
  13. JFrame z = new JFrame();
  14.  
  15. while(true)
  16. {
  17. String name=JOptionPane.showInputDialog(z,"...............Converter...............\n1.Celsius to Fahrenheit\n2.Fahrenheit to Celsius\n3.Celsius to Kalvin\n4.Kalvin to Celcius\n5.Fahrenheit to Kelvin\n6.Kalvin to Fahrenheit\n0.Exit\n\n\n.....What do you want to convert.......\nPlease enter your number : ");
  18.  
  19. int n=Integer.parseInt(name);
  20. if(n==0)
  21. {
  22. break;
  23. }
  24.  
  25. else if(n==1)
  26. {
  27. ctof(celsius, fahrenheit);
  28. }
  29. else if(n==2)
  30. {
  31. ftoc(celsius, fahrenheit);
  32. }
  33. else if(n==3)
  34. {
  35. ctok(celsius, kalvin);
  36. }
  37. else if(n==4)
  38. {
  39. ktoc(celsius, kalvin);
  40. }
  41. else if(n==5)
  42. {
  43. ftok(fahrenheit, kalvin);
  44. }
  45. else if(n==6)
  46. {
  47. ktof(fahrenheit, kalvin);
  48. }
  49. else
  50. {
  51. JOptionPane.showMessageDialog(null,"Your Number is Envalid");
  52. }
  53. System.out.print("\n\n\n\n");
  54. }
  55. }
  56.  
  57. static void ctof(double c, double f)
  58. {
  59. Scanner sc = new Scanner(System.in);
  60. JFrame z = new JFrame();
  61. String name=JOptionPane.showInputDialog(z,"Enter Celsius Temparature : ");
  62. c=Integer.parseInt(name);
  63. f = (c * 9 / 5) + 32;
  64. JOptionPane.showMessageDialog(null,"Fahrenheit Temparature = "+f);
  65. }
  66. static void ftoc(double c, double f)
  67. {
  68. Scanner sc = new Scanner(System.in);
  69. JFrame z = new JFrame();
  70. String name=JOptionPane.showInputDialog(z,"Enter Fahrenheit Temparature : ");
  71. f=Integer.parseInt(name);
  72. c = (f - 32) * 5/9 ;
  73. JOptionPane.showMessageDialog(null,"Celsius Temparature = "+c);
  74. }
  75. static void ctok(double c, double k)
  76. {
  77. Scanner sc = new Scanner(System.in);
  78. JFrame z = new JFrame();
  79. String name=JOptionPane.showInputDialog(z,"Enter Celsius Temparature : ");
  80. c=Integer.parseInt(name);
  81. k = c + 273.15;
  82. JOptionPane.showMessageDialog(null,"Kalvin Temparature = "+k);
  83. }
  84. static void ktoc(double c, double k)
  85. {
  86. Scanner sc = new Scanner(System.in);
  87. JFrame z = new JFrame();
  88. String name=JOptionPane.showInputDialog(z,"Enter Kalvin Temparature : ");
  89. k=Integer.parseInt(name);
  90. c = k - 273.15;
  91. JOptionPane.showMessageDialog(null,"Celsius Temparature = "+c);
  92. }
  93. static void ftok(double f, double k)
  94. {
  95. Scanner sc = new Scanner(System.in);
  96. JFrame z = new JFrame();
  97. String name=JOptionPane.showInputDialog(z,"Enter Fahrenheit Temparature : ");
  98. f=Integer.parseInt(name);
  99. k = (f - 32) * 5/9 + 273.15;
  100. JOptionPane.showMessageDialog(null,"Kalvin Temparature = "+k);
  101. }
  102. static void ktof(double f, double k)
  103. {
  104. Scanner sc = new Scanner(System.in);
  105. JFrame z = new JFrame();
  106. String name=JOptionPane.showInputDialog(z,"Enter Kalvin Temparature : ");
  107. k=Integer.parseInt(name);
  108. f =(k - 273.15) * 9/5 + 32;
  109. JOptionPane.showMessageDialog(null,"Fahrenheit Temparature = "+f);
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement