Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package temparaturedemo;
- import java.util.Scanner;
- import javax.swing.*;
- public class TemparatureDemo {
- public static void main(String[] args) {
- double celsius = 0, fahrenheit=0, kalvin=0;
- Scanner sc = new Scanner(System.in);
- JFrame z = new JFrame();
- while(true)
- {
- 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 : ");
- int n=Integer.parseInt(name);
- if(n==0)
- {
- break;
- }
- else if(n==1)
- {
- ctof(celsius, fahrenheit);
- }
- else if(n==2)
- {
- ftoc(celsius, fahrenheit);
- }
- else if(n==3)
- {
- ctok(celsius, kalvin);
- }
- else if(n==4)
- {
- ktoc(celsius, kalvin);
- }
- else if(n==5)
- {
- ftok(fahrenheit, kalvin);
- }
- else if(n==6)
- {
- ktof(fahrenheit, kalvin);
- }
- else
- {
- JOptionPane.showMessageDialog(null,"Your Number is Envalid");
- }
- System.out.print("\n\n\n\n");
- }
- }
- static void ctof(double c, double f)
- {
- Scanner sc = new Scanner(System.in);
- JFrame z = new JFrame();
- String name=JOptionPane.showInputDialog(z,"Enter Celsius Temparature : ");
- c=Integer.parseInt(name);
- f = (c * 9 / 5) + 32;
- JOptionPane.showMessageDialog(null,"Fahrenheit Temparature = "+f);
- }
- static void ftoc(double c, double f)
- {
- Scanner sc = new Scanner(System.in);
- JFrame z = new JFrame();
- String name=JOptionPane.showInputDialog(z,"Enter Fahrenheit Temparature : ");
- f=Integer.parseInt(name);
- c = (f - 32) * 5/9 ;
- JOptionPane.showMessageDialog(null,"Celsius Temparature = "+c);
- }
- static void ctok(double c, double k)
- {
- Scanner sc = new Scanner(System.in);
- JFrame z = new JFrame();
- String name=JOptionPane.showInputDialog(z,"Enter Celsius Temparature : ");
- c=Integer.parseInt(name);
- k = c + 273.15;
- JOptionPane.showMessageDialog(null,"Kalvin Temparature = "+k);
- }
- static void ktoc(double c, double k)
- {
- Scanner sc = new Scanner(System.in);
- JFrame z = new JFrame();
- String name=JOptionPane.showInputDialog(z,"Enter Kalvin Temparature : ");
- k=Integer.parseInt(name);
- c = k - 273.15;
- JOptionPane.showMessageDialog(null,"Celsius Temparature = "+c);
- }
- static void ftok(double f, double k)
- {
- Scanner sc = new Scanner(System.in);
- JFrame z = new JFrame();
- String name=JOptionPane.showInputDialog(z,"Enter Fahrenheit Temparature : ");
- f=Integer.parseInt(name);
- k = (f - 32) * 5/9 + 273.15;
- JOptionPane.showMessageDialog(null,"Kalvin Temparature = "+k);
- }
- static void ktof(double f, double k)
- {
- Scanner sc = new Scanner(System.in);
- JFrame z = new JFrame();
- String name=JOptionPane.showInputDialog(z,"Enter Kalvin Temparature : ");
- k=Integer.parseInt(name);
- f =(k - 273.15) * 9/5 + 32;
- JOptionPane.showMessageDialog(null,"Fahrenheit Temparature = "+f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement