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

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




Declaring variables, through user input

 
Reply to this topicStart new topic

Declaring variables, through user input

michael351
30 Jan, 2008 - 02:16 PM
Post #1

New D.I.C Head
*

Joined: 29 Jan, 2008
Posts: 12

Can someone help my code. I want to be able to declare variables though user input, i have figured out the code on double, but not string.

My current code is this.
...................................................................................................................
import javax.swing.JOptionPane;

public class test

{

//class header

double celsiusValue = 0.0; //declares celsiusValue as a double variable
double kelvinValue = 0.0; //declares kelvinValue as a double variable
// String madMax;

public test()
{
System.out.println("Servers Calculation");
}
{

//constructor header


String userInput = JOptionPane.showInputDialog("Enter Fahrenheit temperature");


//System.out.println(userInput);


celsiusValue = Double.parseDouble(userInput);

kelvinValue = celsiusValue; //- 273.0;

// madMax = (userInput);


System.out.println(kelvinValue);



//String userInput = JOptionPane.showInputDialog("Enter Word");

// System.out.println(userInput);
}

public static void main (String[] args)

{//main

new test();//instantiation

}
}

..............................................................................................................

And also, how can i get a couple of Option panels on this code, with questions going to a double variable and string variable.

Thanks

Michael.
User is offlineProfile CardPM
+Quote Post

capty99
RE: Declaring Variables, Through User Input
30 Jan, 2008 - 02:21 PM
Post #2

the real kya
Group Icon

Joined: 26 Apr, 2001
Posts: 9,259



Thanked: 16 times
Dream Kudos: 550
My Contributions
your userInput variable is the same in stirng and double

i changed the
CODE

//String userInput = JOptionPane.showInputDialog("Enter Word");

// System.out.println(userInput);


to
CODE

String userInput2 = JOptionPane.showInputDialog("Enter Word");

System.out.println(userInput2);


and it worked. pretty ez fix, am i missing something.
User is online!Profile CardPM
+Quote Post

michael351
RE: Declaring Variables, Through User Input
30 Jan, 2008 - 02:37 PM
Post #3

New D.I.C Head
*

Joined: 29 Jan, 2008
Posts: 12

how can I display the question in the dos prompt aswell?
User is offlineProfile CardPM
+Quote Post

capty99
RE: Declaring Variables, Through User Input
30 Jan, 2008 - 05:54 PM
Post #4

the real kya
Group Icon

Joined: 26 Apr, 2001
Posts: 9,259



Thanked: 16 times
Dream Kudos: 550
My Contributions
don't put it in a popup>?
User is online!Profile CardPM
+Quote Post

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

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