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

Home Answers Viewqa Java-Beginners Convert Miles To Kilometers program in java

Have Programming Question? Ask it here!

Antonio
Convert Miles To Kilometers program in java
1 Answer(s)      2 years ago
Posted in : Java Beginners

Write a program to compute a table of distance conversions between miles and kilometres. You should create a main method which accepts three numbers on the command line as user input: these numbers will be the smallest, largest and step size for constructing the table. The program should then print out a table of converted values to 2 decimal places. You will need to write a separate method to convert a single distance in miles into kilometres. Create and run some unit tests for your program. Extend your program to support conversion from kilometres to miles. Use an extra input argument to tell the program whether to convert from kilometres to miles or from miles to kilometres.

March 5, 2012 at 1:30 PM

```import java.io.*;
import java.util.*;
class Converter {

public void convertDistance(){
System.out.println("1 KM to Miles");
System.out.println("2 Miles to KM");
System.out.println("3 Exit");

Scanner input=new Scanner(System.in);
System.out.print("Enter your choice: ");
int choice=input.nextInt();
switch(choice){
case 1:
int km[]=new int[3];
double miles[]=new double[3];
System.out.println("Enter distance in KM: ");
for(int i=0;i<km.length;i++){
km[i]=input.nextInt();
miles[i] = km[i] * 0.621;
}
System.out.println("KMS \t Miles");
for(int i=0;i<km.length;i++){
System.out.println(km[i]+"\t"+miles[i]);
}
break;
case 2:
int mile[]=new int[3];
double kms[]=new double[3];
System.out.println("Enter distance in Miles: ");
for(int i=0;i<mile.length;i++){
mile[i]=input.nextInt();
kms[i] = mile[i]/ 0.621;
}
System.out.println("Miles \t KMS");
for(int i=0;i<mile.length;i++){
System.out.println(mile[i]+"\t"+kms);
}
break;
case 3:
System.exit(0);
break;
}
}
public static void main(String[] args){
Converter convert=new Converter();
convert.convertDistance();
}
}
```

Related Tutorials/Questions & Answers:
Convert Miles To Kilometers program in java
Convert Miles To Kilometers program in java  Write a program... input argument to tell the program whether to convert from kilometres to miles... in miles into kilometres. Create and run some unit tests for your program
Convert Miles To Kilometers
Convert Miles To Kilometers     ... to Kilometers. The following program helps you in converting Miles to Kilometers.  Code Description: To convert Miles to Kilometers we have used a formula
Programming: Convert Miles to Kilometers
Java NotesProgramming: Convert Miles to Kilometers Name ________________________________ Description Write a program which inputs miles (a double) and displays the equivalent number of kilometers. Assume there are 1.61 kilometers
Kilometers to Miles - Complete
Java NotesExample - Kilometers to Miles - Complete Here is the entire.../KmToMiles.java - Converts Kilometers to Miles. // Fred Swartz, 2004-10-28 import java.awt.... convertKmToMi(double kilometers) { // Assume there are 0.621 miles in a kilometer
Dialog I/O: Kilometers to Miles with Method
Java NotesDialog I/O: Kilometers to Miles with Method  This program is the same as Kilometers to Miles, but with one change: the conversion.../KmToMilesMethod.java // Purpose: Convert kilometers to miles using a method. JOptionPane IO
Dialog I/O: Kilometers to Miles
Java NotesDialog I/O: Kilometers to Miles This basic program asks the user for a number of miles and converts it to kilometers. It uses JOptionPane... 2 //... Computation miles = kilometers * MILES_PER
Kilometers to Miles - User Interface Only
Java NotesExample - Kilometers to Miles - User Interface Only This program produces a user interface, but there is no listener for the button so... characteristics this.setTitle("Kilometers to Miles"); }//end constructor
Kilometer to Miles - Formatted
Java NotesKilometer to Miles - Formatted This program is the same as Kilometers to Miles, but it formats the output to display the output to only...-dialogKmToMiles.java // Purpose: Converts kilometers to miles. Formats output. // Author
Convert Meters To Miles
Convert Meters To Miles       In this section, you will learn to convert Meters To Miles. The following program helps you in converting Meters To Miles.  Code
Java: Kilometer to Miles - IO Class
Java NotesKilometer to Miles - IO Class 1 2 3 4 5 6... kilometers to miles. // Michael Maus, 9 Sept 2004 // // Note: Move input methods... of kilometers."); //... Computation miles = kilometers
Generic Calc
Java NotesExample - Generic Calc This program converts miles into kilometers. It provides a basic plan for making a program that, when a button...(); this.setTitle("Miles to Kilometers"); this.setResizable(false
Kilometers per Liter to Miles per Gallon
Kilometers per Liter to Miles per Gallon   ... the kilometers per liter into miles per gallon then there is one formula...;ConversionTable of Kilometers perLiter and Miles per Gallon </title> <
Convert Inches to Centimeters
Convert Inches To Centimeters       In this section, you will learn to convert Inches to Centimeters. The following program helps you in converting Inches to Centimeters
Java program - convert words into numbers?
Java program - convert words into numbers?   convert words into numbers?   had no answer sir
java program to convert decimal in words
java program to convert decimal in words  write a java program to convert a decimal no. in words.Ex: give input as 12 output must be twelve
Convert To Java Program - Java Beginners
Convert To Java Program  Can anyone convert this C program codes to Java codes,please...thanks! #include int array[20]; int dcn; int cntr=0; void add(); void del(); void insert(); void display(); void exit(); void
GUI convert to celsius program - Java Beginners
GUI convert to celsius program  how to write java GUI program to convert Fahrenheit to Celsius that need user to input value of Fahrenheit then click button convert and value of Celsius will display as a output.   Hi
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that displays the following table (note that 1 mile is 1.609 kilometers). Miles Kilometers
source code program - Java Beginners
source code program  I need the source code for a program that converts temperatures from celsius to fahrenheit and vice versa, as well as converting kilometers to miles and vice versa using Java "classes".  Hi
Java programming question - Java Beginners
Java programming question  I want to write a program that converts... kilometers to miles and vice versa using "methods".  Hi Friend, Try...(); System.out.print("Enter unit KM or Miles: "); try{ unit
java programming code - Java Beginners
java programming code  I want to write a program that converts temperatures from celsius to fahrenheit and vice versa. It also converts kilometers to miles and vice versa using classes
How to convert into to String in Java?
How to convert into to String in Java?  Hi, How to convert into to String in Java? Thanks
Convert to java - Java Beginners
Convert to java  Can anyone convert this javascript program codes to Java codes,please...thanks! var iTanggalM = 0; var iTanggalH = 0; var iBulanM = 0; var iBulanH = 0; var iTahunM = 0; var iTahunH = 0; var
How to convert string to byte in Java
How to convert string to byte in Java  How to convert string to byte in Java
Java Program
Java Program for accepting numbers from 1 - 999 and printing them in form... in form of words   Java Convert Number to Words The given code accept... big numbers, then go through the following link: Java Convert Numbers to Words
how to convert string to image in java
how to convert string to image in java  how to convert string to image in java? I know we need to convert image to a byte array at some point in my application but do not know how to convert a image into byte string. Please
Number Convert - Java Beginners
Some value like 234.Value can be convert into Two Hundred and Thirty Four Rupees Only.Plz send me the program ASAP. Thanks & Regards, VijayaBabu.M  Hi... passString(int number){ int num, q ; if (number < 10 ){ displayOutput(a[number
convert to java plss - Java Beginners
convert to java plss  hi i am using microsoft VB6.0 and my friend ask me to make java program to convert number to words but i only use visual basic because i dont know much in java plss convert it to me this is my code
To convert Speech to Text in java
To convert Speech to Text in java  package abc; import javax.speech.*; import javax.speech.recognition.*; import java.io.FileReader; import java.util.Locale; public class HelloWorld extends ResultAdapter { static Recognizer
convert java Application to Java Applet
convert java Application to Java Applet  hi every Java Master or Java Professional , my Name Is Vincent i'm java beginner can i ask a question regarding for Java application convert to Java Applet. below her is my sample
convert an pdf file to html in Java
convert an pdf file to html in Java  Hi all, How to convert an pdf file to html in Java? Currently all my data is generated into a report in pdf... implementing this, is there any source code in java? Thanks
Java convert file to byte array
Java convert file to byte array  How to convert file to byte array in Java? Thanks   Hi, To convert file to byte array in Java you have to follow the following steps: a) Create the object of InputStream class b
convert java Application to Java Applet
convert java Application to Java Applet  hi every Java Master or Java Professional , my Name Is Vincent i'm java beginner can i ask a question regarding for Java application convert to Java Applet. below her is my sample
Convert text file to XML file in Java
Convert text file to XML file Java In this section, you will learn how to convert the text file into xml file in Java language. To do this, we have used StreamResult which acts as an holder for a transformation result in XML. After
Convert Class File to .java File - Java Beginners
Convert Class File to .java File  Sir, How To Convert .class file to .java File. Please Help me  Use cavaj software ,which is freeware, to convert .class to .java  Use jd-gui to convert ur .class to .java
convert Html to Xhtml - Java Beginners
convert Html to Xhtml  Hi All, I am trying to convert html to xhtml in java. to do this i am using htmlcleaner api. i am not able to do with it.i ve not even got basic example on that so please can u send some example
java program for
java program for   java program for printing documents,images and cards
Java code to convert pdf file to word file
Java code to convert pdf file to word file  How to convert pdf file to word file using Java
java Application Convert to java Applet
java Application Convert to java Applet  Hi every Java Masters i'm Java beginner ,and i want below this figures source code convert to Java Applet hope every Masters can helping thank . import java.util.*; import java.text.
Java Program
Java Program  A Java Program that print the data on the printer but buttons not to be printed
how to convert Visual c++ to java - Java Beginners
how to convert Visual c++ to java  Hi Sakthi here.. How to convert Visual c++ codings to Java codings.. Does both have any similarity in library files
a Java program
a Java program    Write a Java program to print even numbers from 2 to 1024? Write a Java program to print ? My Name is Mirza? 100 times? Write a Java program to print Fibonacci Series? Write a Java program to reverse a number
java program
java program  write a program to print 1234 567 89 10
java program
java program  how to write an addition program in java without using arithematic operator
java program
java program  write java program for constructor,overriding,overriding,exception handling
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  write a java program to display array list and calculate the average of given array
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
java program
java program  java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
java program
java program  Write a java program to do matrix addition operation On two given matrices