Welcome to Dream.In.Code
Become a Java Expert!

Join 150,153 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,361 people online right now. Registration is fast and FREE... Join Now!




How to assign JOptionpane as a double

 
Reply to this topicStart new topic

How to assign JOptionpane as a double

icde4fn
22 Aug, 2008 - 08:20 PM
Post #1

New D.I.C Head
*

Joined: 22 Aug, 2008
Posts: 5

So im making a km to Nautical miles converter. I managed to do it useing keyboard reader but want to do it
using JOptionpane. I cant figure out how to have the user input a double. I know there are a few more errors but thats the big issue right now.


CODE
/*
8/22/08
km-naut */

import javax.swing.JOptionPane;
import TerminalIO.KeyboardReader;


public class nauticalmilesandjo

{
public static void main(String [] args)
{
JOptionPane.showInputDialog("Enter metric unit ");

double nauticalmiles;





nauticalmiles =(km*5400.0)/10000.0;

JOptionPane.showMessageDialog(null,"the equivilent in nautical miles is ");
}

User is offlineProfile CardPM
+Quote Post

fsloke
RE: How To Assign JOptionpane As A Double
22 Aug, 2008 - 11:00 PM
Post #2

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
The answer should be....

CODE

import javax.swing.JOptionPane;

public class nauticalmilesandjo
{  
public static void main(String [] args)
{
String km = JOptionPane.showInputDialog("Enter metric unit ");
double nauticalmiles;
nauticalmiles =(Double.parseDouble(km)*5400.0)/10000.0;
JOptionPane.showMessageDialog(null,"the equivilent in nautical miles is "+ nauticalmiles);
}
}


Every value take from JOptionPane is a String type. You should parse it to Double. SO you can do your calculation...

Understood?
User is offlineProfile CardPM
+Quote Post

icde4fn
RE: How To Assign JOptionpane As A Double
23 Aug, 2008 - 11:24 AM
Post #3

New D.I.C Head
*

Joined: 22 Aug, 2008
Posts: 5

QUOTE(fsloke @ 23 Aug, 2008 - 12:00 AM) *

The answer should be....

CODE

import javax.swing.JOptionPane;

public class nauticalmilesandjo
{  
public static void main(String [] args)
{
String km = JOptionPane.showInputDialog("Enter metric unit ");
double nauticalmiles;
nauticalmiles =(Double.parseDouble(km)*5400.0)/10000.0;
JOptionPane.showMessageDialog(null,"the equivilent in nautical miles is "+ nauticalmiles);
}
}


Every value take from JOptionPane is a String type. You should parse it to Double. SO you can do your calculation...

Understood?


yeah thanks man smile.gif

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:35AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month