Yet another tool. This tool will help you to convert temperature values between Celsius, Kelvin, and Fahrenheit scales.
Java Program :
import java.io.*;
class temp_convert
{
static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int opt;
int t=1;
double c;
double i=0;
double s=0;
System.out.println("\t\t*****Welcome to temperature converter*****");
while(t!=0)
{
System.out.println("\nPress 1 to convert degree celsius into degree fahrenheit");
System.out.println("Press 2 to convert degree fahrenheit into degree celsius");
System.out.println("Press 3 to convert degree celsius into kelvin temp.");
System.out.println("Press 4 to convert degree fahrenheit into kelvin temp.");
System.out.println("Press 5 to convert kelvin temp. into degree celsius");
System.out.println("Press 6 to convert kelvin temp. into degree fahrenheit");
System.out.print("\nEnter you choice : ");
opt=Integer.parseInt(br.readLine());
System.out.print("\n");
switch(opt)
{
case 1:
System.out.print("Enter degree celsius temp.(without the degree sign.) : ");
c=Integer.parseInt(br.readLine());
s=s+celsius(c);
break;
case 2:
System.out.print("Enter degree fahrenheit temp.(without the degree sign.) : ");
c=Integer.parseInt(br.readLine());
s=s+fahr(c);
break;
case 3:
System.out.print("Enter degree celsius temp.(without the degree sign.) : ");
c=Integer.parseInt(br.readLine());
s=s+kelvin(c);
break;
case 4:
System.out.print("Enter degree fahrenheit temp.(without the degree sign.) : ");
c=Integer.parseInt(br.readLine());
i=i+fahr(c);
s=s+kelvin(i);
break;
case 5:
System.out.print("Enter kelvin temp. : ");
c=Integer.parseInt(br.readLine());
s=s+kc(c);
break;
case 6:
System.out.print("Enter kelvin temp. : ");
c=Integer.parseInt(br.readLine());
i=i+kc(c);
s=s+celsius(i);
break;
default:
System.out.print("Invalid option\n");
}
if(opt==1)
System.out.println("\nThe result is : "+s+" degree fahrenheit");
if(opt==2)
System.out.println("\nThe result is : "+s+" degree celsius");
if(opt==3)
System.out.println("\nThe result is : "+s+" kelvin");
if(opt==4)
System.out.println("\nThe result is : "+s+" kelvin");
if(opt==5)
System.out.println("\nThe result is : "+s+" degree celsius");
if(opt==6)
System.out.println("\nThe result is : "+s+" degree fahrenheit");
if(opt!=1 && opt!=2 && opt!=3 && opt!=4 && opt!=5 && opt!=6)
System.out.println("Please try again");
s=0;
i=0;
System.out.println("\nEnter 1 to restart");
System.out.println("Enter 0 to terminate the program");
System.out.print("\nEnter yout choice : ");
t=Integer.parseInt(br.readLine());
}
System.out.println("\nThank you for using this short program");
}
static double celsius(double d)
{
double w=0;
w=((9*d)/5)+32;
return w;
}
static double fahr(double e)
{
double x=0;
x=((e-32)*5)/9;
return x;
}
static double kelvin(double g)
{
double y=0;
y=g+273;
return y;
}
static double kc(double h)
{
double z=0;
z=h-273;
return z;
}
}
Java Program :
import java.io.*;
class temp_convert
{
static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int opt;
int t=1;
double c;
double i=0;
double s=0;
System.out.println("\t\t*****Welcome to temperature converter*****");
while(t!=0)
{
System.out.println("\nPress 1 to convert degree celsius into degree fahrenheit");
System.out.println("Press 2 to convert degree fahrenheit into degree celsius");
System.out.println("Press 3 to convert degree celsius into kelvin temp.");
System.out.println("Press 4 to convert degree fahrenheit into kelvin temp.");
System.out.println("Press 5 to convert kelvin temp. into degree celsius");
System.out.println("Press 6 to convert kelvin temp. into degree fahrenheit");
System.out.print("\nEnter you choice : ");
opt=Integer.parseInt(br.readLine());
System.out.print("\n");
switch(opt)
{
case 1:
System.out.print("Enter degree celsius temp.(without the degree sign.) : ");
c=Integer.parseInt(br.readLine());
s=s+celsius(c);
break;
case 2:
System.out.print("Enter degree fahrenheit temp.(without the degree sign.) : ");
c=Integer.parseInt(br.readLine());
s=s+fahr(c);
break;
case 3:
System.out.print("Enter degree celsius temp.(without the degree sign.) : ");
c=Integer.parseInt(br.readLine());
s=s+kelvin(c);
break;
case 4:
System.out.print("Enter degree fahrenheit temp.(without the degree sign.) : ");
c=Integer.parseInt(br.readLine());
i=i+fahr(c);
s=s+kelvin(i);
break;
case 5:
System.out.print("Enter kelvin temp. : ");
c=Integer.parseInt(br.readLine());
s=s+kc(c);
break;
case 6:
System.out.print("Enter kelvin temp. : ");
c=Integer.parseInt(br.readLine());
i=i+kc(c);
s=s+celsius(i);
break;
default:
System.out.print("Invalid option\n");
}
if(opt==1)
System.out.println("\nThe result is : "+s+" degree fahrenheit");
if(opt==2)
System.out.println("\nThe result is : "+s+" degree celsius");
if(opt==3)
System.out.println("\nThe result is : "+s+" kelvin");
if(opt==4)
System.out.println("\nThe result is : "+s+" kelvin");
if(opt==5)
System.out.println("\nThe result is : "+s+" degree celsius");
if(opt==6)
System.out.println("\nThe result is : "+s+" degree fahrenheit");
if(opt!=1 && opt!=2 && opt!=3 && opt!=4 && opt!=5 && opt!=6)
System.out.println("Please try again");
s=0;
i=0;
System.out.println("\nEnter 1 to restart");
System.out.println("Enter 0 to terminate the program");
System.out.print("\nEnter yout choice : ");
t=Integer.parseInt(br.readLine());
}
System.out.println("\nThank you for using this short program");
}
static double celsius(double d)
{
double w=0;
w=((9*d)/5)+32;
return w;
}
static double fahr(double e)
{
double x=0;
x=((e-32)*5)/9;
return x;
}
static double kelvin(double g)
{
double y=0;
y=g+273;
return y;
}
static double kc(double h)
{
double z=0;
z=h-273;
return z;
}
}
No comments:
Post a Comment