Another distance conversion

Another distance conversion

Write an application that reads a distance in metres. The program will then convert the distance to kilometres, feet and inches, by calling methods. The converted distances will be printed.
? Write a method for each conversion ? toKilometres(), toFeet(), and toInches().

Sample output:

500 metres are
500 * 0.001 = 0.5 kilometres
500 * 3.281 = 1640.5 feet
500 * 39.37 = 19685 inches
View Answers

August 12, 2010 at 10:14 AM

import java.io.*;
public class DistanceConversion{
public static double toKilometres(double value){
double kmValue = value*0.001;
return kmValue;
}
public static double toFeet(double value){
double feetValue = value*3.281;
return feetValue;
}
public static double toInches(double value){
double inchValue = value*39.37;
return inchValue;
}
public static void main(String args[]){
System.out.print("Enter distance in meters : ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String distance=null;
try{
distance = br.readLine();
}
catch(Exception e){
System.out.println(e);
}
double value=Double.parseDouble(distance);
System.out.println(distance+" meters are");
//System.out.println("Entered Value is in int..: "+value);
double kmValue = toKilometres(value);
System.out.println(distance+" * 0.001 = "+kmValue+" kilometers");
double feetValue =toFeet(value);
System.out.println(distance+" * 3.281 = "+feetValue+" feet");
double inchValue =toInches(value);
System.out.println(distance+" * 39.37 = "+inchValue+" inches");


}
}









Related Tutorials/Questions & Answers:
Another distance conversion - Java Beginners
Another distance conversion  Write an application that reads a distance in metres. The program will then convert the distance to kilometres, feet... a method for each conversion ? toKilometres(), toFeet(), and toInches
Distance conversion - Java Beginners
Distance conversion  Write an application that reads a distance in metres. The program will then present a user menu of conversion types, converting the distance to kilometres, feet and inches, according to the user?s selection
Advertisements
Data Conversion from int to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from int primitive type to another data type like String, boolean and char etc
Data Conversion from short to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from short primitive type to another data type like String, boolean and char etc
Data Conversion from float to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from float primitive type to another data type like String, boolean and char etc
Data Conversion from double to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from double primitive type to another data type like String, boolean and char etc
Data Conversion from long to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from long primitive type to another data type like String, boolean and char etc
Data Conversion from String to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from String primitive type to another data type like int, boolean and char etc
Data Conversion from byte to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from byte primitive type to another data type like String, boolean and char etc
class distance
class distance  class distance-integer data member km1,km2,km3,m1,m2,m3. run()-to input the two distance and add them in the third. display()-to display the total distance. display the constructor if required
conversion Applet
conversion Applet  I am a java beginner.................. strong texthow to create JApplet that prompts the user to enter a distance in miles in a JTextField and then converts mile to kilometers and display the result as XX.XX
Edit Distance
Edit Distance  I want java programming ask from user input two string and the program find the edit distance between two strings and find table and optimal solution using GUI
ModuleNotFoundError: No module named 'Distance'
ModuleNotFoundError: No module named 'Distance'  Hi, My Python... 'Distance' How to remove the ModuleNotFoundError: No module named 'Distance... to install padas library. You can install Distance python with following
Delhi to Udaipur by road distance
Delhi to Udaipur by road distance  delhi to udaipur by road distance
distance data science masters
distance data science masters  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: distance... that I can learn the topic "distance data science masters". Also tell me
machine learning distance learning
machine learning distance learning  Hi, I am beginner in Data...: machine learning distance learning Try to provide me good examples or tutorials links so that I can learn the topic "machine learning distance learning"
data science distance learning
data science distance learning  Hi, I am beginner in Data Science... science distance learning Try to provide me good examples or tutorials links so that I can learn the topic "data science distance learning". Also tell
data analytics distance learning
data analytics distance learning  Hi, I am beginner in Data Science... analytics distance learning Try to provide me good examples or tutorials links so that I can learn the topic "data analytics distance learning"
artificial intelligence distance learning
artificial intelligence distance learning  Hi, I am beginner in Data...: artificial intelligence distance learning Try to provide me good examples... distance learning". Also tell me which is the good training courses
ai distance learning
ai distance learning  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: ai distance... the topic "ai distance learning". Also tell me which is the good training
currency conversion
currency conversion   hi frds.. I wan jsp code to convert currency in different formats??... if u know plz plz plz post it   Please visit the following link: http://www.roseindia.net/tutorials/I18N/currency
Distance in meters - Java Beginners
Distance in meters  Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selections... the program The program will convert the distance to kilometers, inches
ModuleNotFoundError: No module named 'distance-locker'
ModuleNotFoundError: No module named 'distance-locker'  Hi, My... named 'distance-locker' How to remove the ModuleNotFoundError: No module named 'distance-locker' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'edit-distance'
ModuleNotFoundError: No module named 'edit-distance'  Hi, My... 'edit-distance' How to remove the ModuleNotFoundError: No module named 'edit-distance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'trajectory_distance'
ModuleNotFoundError: No module named 'trajectory_distance'  Hi, My... named 'trajectory_distance' How to remove the ModuleNotFoundError: No module named 'trajectory_distance' error? Thanks   Hi
ModuleNotFoundError: No module named 'distance-locker'
ModuleNotFoundError: No module named 'distance-locker'  Hi, My... named 'distance-locker' How to remove the ModuleNotFoundError: No module named 'distance-locker' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'edit-distance'
ModuleNotFoundError: No module named 'edit-distance'  Hi, My... 'edit-distance' How to remove the ModuleNotFoundError: No module named 'edit-distance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'faces-distance'
ModuleNotFoundError: No module named 'faces-distance'  Hi, My... named 'faces-distance' How to remove the ModuleNotFoundError: No module named 'faces-distance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'distance-metrics'
ModuleNotFoundError: No module named 'distance-metrics'  Hi, My... named 'distance-metrics' How to remove the ModuleNotFoundError: No module named 'distance-metrics' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'faces-distance'
ModuleNotFoundError: No module named 'faces-distance'  Hi, My... named 'faces-distance' How to remove the ModuleNotFoundError: No module named 'faces-distance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'string-distance'
ModuleNotFoundError: No module named 'string-distance'  Hi, My... named 'string-distance' How to remove the ModuleNotFoundError: No module named 'string-distance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'tree_distance'
ModuleNotFoundError: No module named 'tree_distance'  Hi, My... 'tree_distance' How to remove the ModuleNotFoundError: No module named 'tree_distance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Brew-Distance'
ModuleNotFoundError: No module named 'Brew-Distance'  Hi, My... 'Brew-Distance' How to remove the ModuleNotFoundError: No module named 'Brew-Distance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'categorical-distance'
ModuleNotFoundError: No module named 'categorical-distance'  Hi...: No module named 'categorical-distance' How to remove the ModuleNotFoundError: No module named 'categorical-distance' error? Thanks   Hi
ModuleNotFoundError: No module named 'dask-distance'
ModuleNotFoundError: No module named 'dask-distance'  Hi, My... 'dask-distance' How to remove the ModuleNotFoundError: No module named 'dask-distance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'datetime-distance'
ModuleNotFoundError: No module named 'datetime-distance'  Hi, My... named 'datetime-distance' How to remove the ModuleNotFoundError: No module named 'datetime-distance' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'distance-metrics'
ModuleNotFoundError: No module named 'distance-metrics'  Hi, My... named 'distance-metrics' How to remove the ModuleNotFoundError: No module named 'distance-metrics' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-distance'
ModuleNotFoundError: No module named 'django-distance'  Hi, My... named 'django-distance' How to remove the ModuleNotFoundError: No module named 'django-distance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'earth_distance'
ModuleNotFoundError: No module named 'earth_distance'  Hi, My... named 'earth_distance' How to remove the ModuleNotFoundError: No module named 'earth_distance' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'effective-distance'
ModuleNotFoundError: No module named 'effective-distance'  Hi, My... named 'effective-distance' How to remove the ModuleNotFoundError: No module named 'effective-distance' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'jargon-distance'
ModuleNotFoundError: No module named 'jargon-distance'  Hi, My... named 'jargon-distance' How to remove the ModuleNotFoundError: No module named 'jargon-distance' error? Thanks   Hi, In your python
conversion
conversion
mtech in machine learning distance
mtech in machine learning distance  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: mtech in machine learning distance Try to provide me good examples or tutorials
Hill stations near Delhi distance
Hill stations near Delhi distance   Hi, Can any one tell the distances of the Hill stations near Delhi? Thanks
image conversion tools
image conversion tools  how many tools are available in image conversion at particularlly in java
ModuleNotFoundError: No module named 'conversion'
ModuleNotFoundError: No module named 'conversion'  Hi, My Python... 'conversion' How to remove the ModuleNotFoundError: No module named 'conversion' error? Thanks   Hi, In your python environment you
distance learning masters in data science
distance learning masters in data science  Hi, I am beginner in Data...: distance learning masters in data science Try to provide me good examples or tutorials links so that I can learn the topic "distance learning masters
distance learning data science masters
distance learning data science masters  Hi, I am beginner in Data...: distance learning data science masters Try to provide me good examples or tutorials links so that I can learn the topic "distance learning data science
masters in data science distance learning
masters in data science distance learning  Hi, I am beginner in Data...: masters in data science distance learning Try to provide me good examples... distance learning". Also tell me which is the good training courses

Ads