mr6e6o0o
Advanced Recon Specialist
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.
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.
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.
6. After computing, display the equivalent value of kilometers to miles using JOptionPane.showMessageDialog.
Output:
Here's the full code of this tutorial:
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
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.
- import
javax.swing.*
;
- </
java
- 3
. Declare
your variables.
- <
java>
- String
kmStr;
- double
km;
- 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.
- kmStr =
JOptionPane
.showInputDialog
(
null
, "Enter kilometers."
)
;
- 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.
- mi =
km *
0.621
;
6. After computing, display the equivalent value of kilometers to miles using JOptionPane.showMessageDialog.
- JOptionPane
.showMessageDialog
(
null
, km +
" kilometers is "
- +
mi +
" miles."
)
;
Output:

Here's the full code of this tutorial:
- import
javax.swing.*
;
- public
class
kmToMiles {
- public
static
void
main(
String
[
]
args)
{
- String
kmStr;
- double
km;
- double
mi;
- //... Input
- kmStr =
JOptionPane
.showInputDialog
(
null
, "Enter kilometers."
)
;
- km =
Double
.parseDouble
(
kmStr)
;
- //... Computation
- mi =
km *
0.621
;
- //... Output
- JOptionPane
.showMessageDialog
(
null
, km +
" kilometers is "
- +
mi +
" miles."
)
;
- }
- }
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.