UNIT CONVERTER PROJECT

import java.io.*;
public class unit_converter
{
int choice1,choice2;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void inputmenu()throws IOException
{
 System.out.println("1. Temperature");
 System.out.println("2. Distance");
 System.out.println("3. Volume");

 System.out.println("Enter your choice (1-3)");
 choice1=Integer.parseInt(br.readLine());
 calculation();  // calling calculation function
}
public void calculation()throws IOException
{
 switch(choice1)
 {
  case 1:   //start of Temperature menu
  System.out.println("1. Celcius to Fahrenheit ");
  System.out.println("2. Fahrenheit to Celcius");
  System.out.println("3. Celcius to Kelvin");
  System.out.println("4. Kelvin to Celcius");
  System.out.println("5. Kelvin to Fahrenheit");
  System.out.println("6. Fahrenheit to Kelvin");

  System.out.println("Enter your choice (1-6)");
  choice2=Integer.parseInt(br.readLine());

  double C,F,L,CM,GL,K,M,I,ML;
  switch(choice2)
  {
    case 1:  
    System.out.println("Enter temperature in Celcius");
    C=Double.parseDouble(br.readLine());
    F=(9*C+160)/5;
    System.out.println("Temperature in Fahrenheit is "+F);
    break;
    
    case 2: 
    System.out.println("Enter temperature in Fahrenheit");
    F=Double.parseDouble(br.readLine());
    C=(5*F-160)/9;
    System.out.println("Temperature in Celcius is "+C);
    break;

    case 3:
    System.out.println("Enter temperature in Celcius");
    C=Double.parseDouble(br.readLine());
    K=273.15+C;
    System.out.println("Temperature in Kelvin is "+K);
    break;

    case 4:
    System.out.println("Enter temperature in Kelvin");
    K=Double.parseDouble(br.readLine());
    C=K-273.15;
    System.out.println("Temperature in Celcius is "+C);
    break;

    case 5:
    System.out.println("Enter temperature in Kelvin");
    K=Double.parseDouble(br.readLine());
    C=K-273.15;
    F=(9*C+160)/5;
    System.out.println("Temperature in Fahrenheit is "+F);
    break;

    case 6:
    System.out.println("Enter temperature in Fahrenheit");
    F=Double.parseDouble(br.readLine());
    C=(5*F-160)/9;
    K=273.15+C;
    System.out.println("Temperature in Kelvin is "+K);
    break;

    default :
    System.out.println("Wrong choice. It should be 1 to 6");
  }//end of temperature choice
  break;
  case 2: //start of Distance menu
  System.out.println("1. Mile to Kilometer");
  System.out.println("2. Kilometer to Mile");
  System.out.println("3. Inch to Meter");
  System.out.println("4. Mile to Inch");
  System.out.println("5. Centimeter to Meter");
  System.out.println("6. Meter to Centimeter");
  
  System.out.println("Enter your choice (1-6)");
  choice2=Integer.parseInt(br.readLine());
  switch(choice2)
  {
    case 1:
    System.out.println("Enter Distance in Mile");
    M=Double.parseDouble(br.readLine());
    K=M*1.60934;
    System.out.println("Distance in Kilometer is "+K);
    break;

    case 2:
    System.out.println("Enter Distance in Kilometer");
    K=Double.parseDouble(br.readLine());
    M=K*0.62137;
    System.out.println("Distance in Mile is "+M);
    break;

    case 3:
    System.out.println("Enter Distance in Inches");
    I=Double.parseDouble(br.readLine());
    M=I*0.0254;
    System.out.println("Distance in Meter is "+M);
    break;

    case 4:
    System.out.println("Enter Distance in Mile");
    M=Double.parseDouble(br.readLine());
    I=M*63360;
    System.out.println("Distance in Inches is "+I);
    break;

    case 5:
    System.out.println("Enter Distance in Centimeter");
    CM=Double.parseDouble(br.readLine());
    M=CM*.01;
    System.out.println("Distance in Meter is "+M);
    break;

    case 6:
    System.out.println("Enter Distance in Meter");
    M=Double.parseDouble(br.readLine());
    CM=M*100;
    System.out.println("Distance in Centimeter is "+CM);
    break;

    default :
    System.out.println("Wrong choice. It should be 1 to 6");
  }//end of Distance choice
  break;
  case 3: //start of Volume menu
  System.out.println("1. Litres to Gallons");
  System.out.println("2. Gallons to Litres");
  System.out.println("3. Litres to Millilitres");
  System.out.println("4. Millilitres to Litres");
  
  System.out.println("Enter your choice (1-4)");
  choice2=Integer.parseInt(br.readLine());
  switch(choice2)
  {
    case 1:
    System.out.println("Enter Volume in Litres");
    L=Double.parseDouble(br.readLine());
    GL=L*0.26417;
    System.out.println("Volume in Gallons(US) is "+GL);
    break;

    case 2:
    System.out.println("Enter Volume in Gallons(US)");
    GL=Double.parseDouble(br.readLine());
    L=GL*3.78541;
    System.out.println("Volume in Litres is "+L);
    break;

    case 3:
    System.out.println("Enter Volume in Litres");
    L=Double.parseDouble(br.readLine());
    ML=L*1000;
    System.out.println("Volume in Millilitres is "+ML);
    break;

    case 4:
    System.out.println("Enter Volume in Millilitres");
    ML=Double.parseDouble(br.readLine());
    L=ML*.001;
    System.out.println("Volume in Litres is "+L);
    break;

    default :
    System.out.println("Wrong choice. It should be 1 to 4");
  }//end of Volume choice
  break;
  default :
  System.out.println("Wrong choice. It should be 1 to 3");
  }//end of main menu choice
}//end of calculation function

public void main()throws IOException
{
  inputmenu();   //invoking inputmenu function
                 //no need to invoke calculation(). It has already called from inputmenu()
} //end of main()
}//end of class
Created by Sanjay Sir of SOFTECH on 30/05/2010
Project home
Free Web Hosting