Length Convertor

3 comments - Post a comment

/* (Length Convertor): Simple Java Program to convert miles, kilometers, meter, feet, centimeter and inches
*/
Enter value for Miles: 45

Kilometer: 72.4185
Meter: 72418.5
Feet: 237593.50429815002
Inches: 2851122.0515778
Centimeter: 7241850.011007612

import java.io.*;

public class ConverterIO
{
public static void main(String[] args) throws IOException
{
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
String strChoose;
int choose;
String strMiles, strKilometer, strMeter, strFeet, strInches, strCentimeter;
double miles, kilometer, meter,feet, inches, centimeter;
boolean done = false;
while (!done)
{
//Getting input from the user
println("\n\n\n\t\tLENGTH CONVERTER");
println("\n\tWhat you would like to convert?");
println("");
println("\t1) Miles 4) Feet");
println("\t2) Kilometer 5) Inches");
println("\t3) Meter 6) Centimeter");
println("\t\t 7) Exit");
print("\n\tEnter your choice: ");
strChoose = dataIn.readLine();
choose = Integer.parseInt(strChoose);

if ((choose < = 0) || (choose >= 8))
{
println("\tInvalid entry, please try again!");
}

switch (choose)
{
case 1:
print("\n\tEnter value for Miles: ");
strMiles = dataIn.readLine();
miles = Double.parseDouble(strMiles);
println("\n\t\tKilometer: " + (miles*1.6093));
println("\t\tMeter: " + (miles*1609.3));
println("\t\tFeet: " + (miles*5279.85565107));
println("\t\tInches: " + (miles*63358.26781284));
println("\t\tCentimeter: " + (miles*160930.0002446136));
break;

case 2:
print("\n\tEnter value for Kilometer: ");
strKilometer = dataIn.readLine();
kilometer = Double.parseDouble(strKilometer);
println("\n\t\tMiles: " + (kilometer*0.6213882));
println("\t\tMeter: " + (kilometer*1000));
println("\t\tFeet: " + (kilometer*3280.8399));
println("\t\tInches: " + (kilometer*39370.0788));
println("\t\tCentimeter: " + (kilometer*100000)); break;

case 3:
print("\n\tEnter value for Meter: ");
strMeter = dataIn.readLine();
meter = Double.parseDouble(strMeter);
println("\n\t\tMiles: " + (meter*621.3882));
println("\t\tKilometer: " + (meter*1000));
println("\t\tFeet: " + (meter*3.2808399));
println("\t\tInches: " + (meter*39.3700788));
println("\t\tCentimeter: " + (meter*100));
break;

case 4:
print("\n\tEnter value for Feet: ");
strFeet = dataIn.readLine();
feet = Double.parseDouble(strFeet);
println("\n\t\tMiles: " + (feet*0.0001893991176));
println("\t\tKilometer: " + (feet*0.0003048));
println("\t\tMeter: " + (feet*0.3048));
println("\t\tInches: " + (feet*12));
println("\t\tCentimeter: " + (feet*30.48));
break;

case 5:
print("\n\tEnter value for Inches: ");
strInches = dataIn.readLine();
inches = Double.parseDouble(strInches);
println("\n\t\tMiles: " + (inches*0.000015783254));
println("\t\tKilometer: " + (inches*0.000025349));
println("\t\tMeter: " + (inches*0.02534));
println("\t\tFeet: " + (inches*0.08333));
println("\t\tCentimeter: " + (inches*2.51));
break;

case 6:
print("\n\tEnter value for Centimeter: ");
strCentimeter = dataIn.readLine();
centimeter = Double.parseDouble(strCentimeter);
println("\n\t\tMiles: " + (centimeter*0.000006218797));
println("\t\tKilometer: " + (centimeter*0.000004));
println("\t\tMeter: " + (centimeter*0.004));
println("\t\tFeet: " + (centimeter*0.032808386877));
println("\t\tInches: " + (centimeter*0.3937008));
break;

case 7:
done = true;
println("\n\tThank you for using this program!");
println("\n\n");
break;

default: throw new NumberFormatException();

} // end switch
} // end while
} // end main

//short cut for print
private static void print(String s)
{
System.out.print(s);
}

//short cut for println
private static void println(String s)
{
System.out.println(s);
}
}

/* Output
LENGTH CONVERTER

What you would like to convert?

1) Miles 4) Feet
2) Kilometer 5) Inches
3) Meter 6) Centimeter
7) Exit

Enter your choice: 1

Enter value for Miles: 45

Kilometer: 72.4185
Meter: 72418.5
Feet: 237593.50429815002
Inches: 2851122.0515778
Centimeter: 7241850.011007612


LENGTH CONVERTER

What you would like to convert?

1) Miles 4) Feet
2) Kilometer 5) Inches
3) Meter 6) Centimeter
7) Exit

Enter your choice: 5

Enter value for Inches: 48.5

Miles: 7.65487819E-4
Kilometer: 0.0012294265
Meter: 1.22899
Feet: 4.041505
Centimeter: 121.73499999999999


LENGTH CONVERTER

What you would like to convert?

1) Miles 4) Feet
2) Kilometer 5) Inches
3) Meter 6) Centimeter
7) Exit

Enter your choice: 7

Thank you for using this program!
*/

 
This Post has 3 Comments Add your own!
Anonymous - June 22, 2012 at 5:35 PM

nice program but how to go to selection menu after covertion finished.

Anonymous - July 20, 2012 at 4:24 PM

to go to selection menu is the "while loop"

Anonymous - September 15, 2012 at 3:18 PM

its difficult but i know this thing that i woud not take computers next year

Post a Comment