Temperature Convertor


/ Published in: Java
Save to your folder(s)

This is written in Java and the code has not been copied from the web


Copy this code and paste it in your HTML
  1. /*
  2.  * Programmer: Waleed Ahsan
  3.  * This program is written by me and this code shall not be copied for any other program
  4.  */
  5.  
  6. import javax.swing.JFrame;
  7. import javax.swing.JOptionPane;
  8.  
  9. public class TemperatureConvertor {
  10. public static void main(String args[])
  11. {
  12. JFrame answerbox = new JFrame();
  13.  
  14. String choice;
  15. String DEGREE = "\u00b0";
  16. double celsius;
  17. double fahrenheit;
  18.  
  19. choice = JOptionPane.showInputDialog("Type 'A' if you want to convert Celsius to Fahrenheit\nType 'B' if you want to convert Fahrenheit to Celsius");
  20.  
  21. if(choice.equals("A") || (choice.equals("a")))
  22. {
  23. celsius = Double.parseDouble(JOptionPane.showInputDialog("What is the Celsius temperature you want to convert?"));
  24. celsius = (celsius * 1.8) + 32;
  25. JOptionPane.showMessageDialog(answerbox, "Your new temperature is " + celsius + DEGREE + "F");
  26. }
  27.  
  28. if(choice.equals("B") || (choice.equals("b")))
  29. {
  30. fahrenheit = Double.parseDouble(JOptionPane.showInputDialog("What is the Fahrenheit temperature you want to convert?"));
  31. fahrenheit = (fahrenheit - 32) * 5/9;
  32. JOptionPane.showMessageDialog(answerbox, "Your new temperature is " + fahrenheit + DEGREE + "C");
  33. }
  34. }
  35. }

URL: https://github.com/WaleedAhsan123

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.