Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Another distance conversion

Have Programming Question? Ask it here!
 
 
 


dylan
Another distance conversion
1 Answer(s)      4 years and a month ago
Posted in : Java Beginners


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

Advertisement
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 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 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 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
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 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 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
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
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
Delhi to Udaipur by road distance
Delhi to Udaipur by road distance  delhi to udaipur by road distance
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
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
Hill stations near Delhi distance
Hill stations near Delhi distance   Hi, Can any one tell the distances of the Hill stations near Delhi? Thanks
GUI and how to convert a distance - Java Beginners
application that can be is used to convert a distance unit in miles into its... conversion is as follows: 1 mile = 2.5 km 1 km = 1000 m 1 meter = 60...=new JTextField(20); t5=new JTextField(20); l1=new JLabel("Enter distance
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
Road distance using Java - Java Beginners
Road distance using Java  Dear All i am calculating the straight line distance between two latlong points using the simple mathematical formula but i need the Real Road Driving Distance // protected double distance(double pX
Distance learning business management
Distance learning business management courses are on high demand today.... But those students should not worry as many institutions have started distance... for the future and skilled workforce. Distance learning business management courses
Hill Stations near Delhi distance
Distance of Major Hill Stations From Delhi  In this page we have listed all the Hill Stations near Delhi with their distance from central Delhi... and northeastern India. List of Hill Stations near Delhi with distance Sr
VoIP Long Distance
VoIP Long Distance          VoIP Designing a Long-Distance Network The long-distance Voice over IP (VoIP) network solution is a set of network design
image conversion tools
image conversion tools  how many tools are available in image conversion at particularlly in java
How can i display the distance of a line drawing randomly?
How can i display the distance of a line drawing randomly?  How can i display the distance of a line drawing randomly
.wav file conversion
.wav file conversion   how to read .wav file and converd the data into text format
conversion of language in a project
conversion of language in a project  how can we convert the database code in the project dynamically
Number conversion in JavaScript
Number conversion in JavaScript  How do you convert numbers between different bases in JavaScript
NSString to float conversion
NSString to float conversion  HI, I my iPhone and iPad application I have to convert NSString to float. Provide me example of NSString to float conversion. Thanks   Hi, Please see NSString to float conversion
object conversion - Java Beginners
object conversion   Hi, Can anybody tell me the object conversion in java.   Hi sandeep Can u please tell me in details about your.../java-conversion/ObjectToDouble.shtml Thanks... sandeep kumar suman
loop to input multiple points to calculate final distance and speed
loop to input multiple points to calculate final distance and speed  ...; private double distance; public Travel() { time=0; distance=0... getDistance() { return distance; } public static void main (String[] args
Conversion - Development process
is the theory of conversion from java to .NET? How it is done?   Hi... Conversion Assistant (JLCA). Code that calls Java APIs can convert to comparable C# code... to a topic with guidelines for modifications needed to finish the conversion
NSString to float conversion
NSString to float conversion  HI, I my iPhone and iPad application I have to convert NSString to float. Provide me example of NSString to float conversion. Thanks   HI, Use the following code: NSScanner *strXpos
Conversion of String to Integer
Conversion of String to Integer  public class Test { public static void main(String[] args) { int countA = 0; int countB = 0; int countC = 0; int countD = 0; int countE = 0; int
javascript integer to string conversion
javascript integer to string conversion  How to Javascript Integer to String Conversion   <script type="text/javascript"> /** * print out the value and the type of the variable passed
Java Conversion Question - Java Beginners
Java Conversion Question   Hello sir ,How i can Convert Java Code to Vb.net ,Plz Help Me
Excel conversion tool. - Java Beginners
Excel conversion tool.  Hi, I need a conversion tool which can convert .xls(Excel 2003) to .xlsx (Excel 2007) and vice-versa. Please suggest any links ro tools. Thank You
hexadecimal conversion java compilation - UML
hexadecimal conversion java compilation  write a simple program..., Please visit the following links: http://www.roseindia.net/java/java-conversion/BinaryToHexa.shtml http://www.roseindia.net/java/java-conversion
Casting (Type Conversion)
to another type. Conversion of data from one type to another type is known as type casting. In java one object reference can be type cast into another object reference... Casting (Type Conversion)      
Data Conversion In Sql Server 2005
Data Conversion In Sql Server 2005  Hi I am working vb.net & sql server 2005 database. I am storing date (MM/DD/YYYY) format. now I have problem in sql date conversion (DD/MM/YYYY). Can you help how to convert date
Introduction to Type conversion in Struts
Introduction to Type conversion in Struts Type conversion is a mechanism... this powerful and important facility. In struts the type conversion is an mechanism... are converted into complex bean properties using this type conversion mechanism
Conversion of unicode to its corresponding character
Conversion of unicode to its corresponding character  i have a string of unicodes e.g String s="\c0059\c0049\c3000" .. i need code for converting these unicodes to its corresponding alphabets.. pls if possible rep asap as i need
Mysql Time Zone Conversion
Mysql Time Zone Conversion       The Tutorial illustrate you an example from 'Mysql Time Zone Conversion' that describes you about the time zone conversion. SYNTAX
Programming: Numeric Conversion
Java NotesProgramming: Numeric Conversion Name ________________________________ Description Write a program which converts a measurement from one system of units to another. Read a number (or numbers) in one system and output
String to Date Conversion - Java Beginners
  Hi friend, For conversion in this format : 11/SEP/2008 07:07:32...)); For read more information : http://www.roseindia.net/java/java-conversion
Conversion In Collections - Java Interview Questions
Conversion In Collections  Hi Friends, can u give code to convert ArrayList to HashMap and HashMap to ArrayList. Thanks Prakash  Hi Friend, 1)Convert ArrayList To HashMap: import java.io.*; import java.util.
conversion of war file into executable jar file
conversion of war file into executable jar file  how to convert war file into executable jar file
Java : String Case Conversion
Java : String Case Conversion In this section we will discuss how to convert a String from one case into another case. Upper to Lower case Conversion... : This example shows conversion of String from one case to another case. '
ArrayList as an argument to another class
ArrayList as an argument to another class  how do you pass arraylists as arguments to another class, and how does the method/class accept this arraylist for use
 

 

 

DMCA.com