• We just launched and are currently in beta. Join us as we build and grow the community.

Kilometer to Miles Converter in Java GUI

mr6e6o0o

Advanced Recon Specialist
M Rep
0
0
0
Rep
0
M Vouches
0
0
0
Vouches
0
Posts
141
Likes
25
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this tutorial, i will teach you how to create a program for converting kilometer to miles in java with GUI. It is necessary for java beginners to undergo and learn this simple program that i have made.

Now, let's start this tutorial!

1. Open JCreator or NetBeans and make a java program with a file name of kmToMiles.java.

2. Import javax.swing package. Hence we will use a GUI (Graphical User Interface) here like the inputting the kilometer.
  1. import

    javax.swing.*

    ;

  2. </

    java
  3. 3

    . Declare

    your variables.
  4. <

    java>
  5. String

    kmStr;
  6. double

    km;
  7. double

    mi;

We will use kmStr as String as an inputbox, variable km for kilometer, and mi for miles.

4. Use variable kmStr as an InputDialogBox for inputting kilometer. And convert the input to double (hence we will input only number here) with the use of variable km.

  1. kmStr =

    JOptionPane

    .showInputDialog

    (

    null

    , "Enter kilometers."

    )

    ;
  2. km =

    Double

    .parseDouble

    (

    kmStr)

    ;

5. Create the code for formula. We all know that 1km is equivalent to 0.621 miles. So, we will use this formula and pass the value to mi variable.

  1. mi =

    km *

    0.621

    ;

6. After computing, display the equivalent value of kilometers to miles using JOptionPane.showMessageDialog.

  1. JOptionPane

    .showMessageDialog

    (

    null

    , km +

    " kilometers is "
  2. +

    mi +

    " miles."

    )

    ;

Output:
km3_0.png


Here's the full code of this tutorial:

  1. import

    javax.swing.*

    ;

  2. public

    class

    kmToMiles {
  3. public

    static

    void

    main(

    String

    [

    ]

    args)

    {

  4. String

    kmStr;
  5. double

    km;
  6. double

    mi;

  7. //... Input
  8. kmStr =

    JOptionPane

    .showInputDialog

    (

    null

    , "Enter kilometers."

    )

    ;
  9. km =

    Double

    .parseDouble

    (

    kmStr)

    ;

  10. //... Computation
  11. mi =

    km *

    0.621

    ;

  12. //... Output
  13. JOptionPane

    .showMessageDialog

    (

    null

    , km +

    " kilometers is "
  14. +

    mi +

    " miles."

    )

    ;
  15. }

  16. }

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook: https://www.facebook.com/donzzsky

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware


Download
You must upgrade your account or reply in the thread to view hidden text.
 

449,093

322,160

322,169

Top