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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Antonio
Convert Miles To Kilometers program in java
1 Answer(s)      2 years and 8 months 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.


Advertisement
View Answers

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
Advertisements
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
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
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 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
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
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 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 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.
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
 

 

 

DMCA.com