Need a little help

Hi this is my first post here.

I need some help with an assignment for my Java Programming class.

Write a program that reads a Fahrenheit degree in double from an input dialog box, then converts it to Celsius and displays the result in a message dialog box. The formula for the conversion is as follows: celsius = (5/9) * (fahrenheit - 32)

Hint: In Java 5/9 is 0, so you need to write 5.0/9 in the program to obtain the correct result.

Here is my code:

import javax.swing.JOptionPane;

public class Convert{

public static void main(String[]args){

int fahrenheit;
double celsius;

//Formula to convert Fahrenheit to Celsius
celsius = (5.0/9) * (fahrenheit -32);

// Prompt user to enter degrees Fahrenheit
JOptionPane.showInputDialog("Enter degrees Fahrenheit");

//Display converted output
JOptionPane.showMessageDialog(fahrenheit + "degrees Fahrenheit = " + celsius + " degress Celsius");
}
}

My original code was slightly different but didn't work either. I've been playing around with this literally for hours and I'm going crazy. Basically I figured out how to get the input box to pop up but I can't figure out how or where to plug the conversion formula in or make it work properly.

The error I get with that code is:

--jGRASP exec: javac -g C:\Program Files\jGRASP\projects\Convert.java

Convert.java:22: cannot resolve symbol
symbol : method showMessageDialog (java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog(fahrenheit + "degrees Fahrenheit = " + celsius + " degress Celsius");
^
1 error

--jGRASP wedge2: exit code for process is 1.
--jGRASP: operation complete.

Any help here would really be appreciated. Its probably something simple that I'm overlooking but I'm not exactly good at programming and my teacher and textbook don't help much either.
[2072 byte] By [Tom in NJ] at [2007-11-19 18:13:47]
# 1 Re: Need a little help
First the JOptionPane.showInputDialog() method returns a String which contains whatever the user inputs into the dialog box. If you want to use this information you have to store it in a variable. Then you have to take the String variable and parse it to an int or a double or whatever is appropriate. Once you have the temperature value as a number you can apply the formula to it. Finally the JOptionPane.showMessageDialog() method takes two parameters, the first is the parent component that the JOptionPane should pop-up over, and the second is the message. Since you don't have a parent frame, this argument should be passed as null. i.e.

JOptionPane.showMessageDialog(null, message)

Hope this helps a little

Garrett
gmrowe1075 at 2007-11-10 2:21:01 >
# 2 Re: Need a little help
I added null to that like you said and now I get this error

--jGRASP exec: javac -g C:\Program Files\jGRASP\projects\Convert.java

Convert.java:16: variable fahrenheit might not have been initialized
celsius = (5.0/9) * (fahrenheit -32);
^
1 error

--jGRASP wedge2: exit code for process is 1.
--jGRASP: operation complete.

--jGRASP exec: javac -g C:\Program Files\jGRASP\projects\Convert.java

Convert.java:16: variable fahrenheit might not have been initialized
celsius = (5.0/9) * (fahrenheit -32);
^
1 error

--jGRASP wedge2: exit code for process is 1.
--jGRASP: operation complete.
Tom in NJ at 2007-11-10 2:22:03 >
# 3 Re: Need a little help
I'm glad you coud read through all my typos in the last post to get to the meat of it ;). You are getting an error message because you haven't assigned any value to the fahrenheit variable. What you need to do now is figure out how to take the information the user enters in the JOptionPane and assign it to the fahrenheit variable. I think I gave you a hint in my first post.

Garrett
gmrowe1075 at 2007-11-10 2:23:04 >
# 4 Re: Need a little help
I'll figure something out lol

Thx for the help man.

I've got tons of other homework to do and I'm putting this little Java program on the backburner until its due Tuesday. I want to finish almost everything before the Super Bowl starts tomorrow.
Tom in NJ at 2007-11-10 2:24:09 >
# 5 Re: Need a little help
to read from the user, replace the following line with:

// Prompt user to enter degrees Fahrenheit
JOptionPane.showInputDialog("Enter degrees Fahrenheit");

fahrenheit=Integer.parseInt( JOptionPane.showInputDialog("Enter degrees Fahrenheit");

& this way fahrenheit will be intialized :)
nvidia at 2007-11-10 2:25:12 >