I attempted to compile your program and looked at the list of errors.
All the errors concerned the results of a
JOptionPane.showInputDialog(String). This method only returns Strings.
You've got them trying to accept chars and ints. You need a temporary
String variable to receive the input from the JOptionPane. After you
have the input, you can convert it to whatever type you need to.
Research Integer.parseInt(String) for ints. If you want a char you'll
have to use an if statement...
On Fri, 2004-11-12 at 01:27, njdude20 wrote:
> I am very new to Java programming and I am taking courses online
> through the University of Maryland. I need help figuring out how to
> fix the problem in one of the programs I am writing. I am entering
> the program in JCreator and when I go to compile the program I get
> an error message of incompatiable types. How do I fix this? Here is
> the file:
> /**
> This program is written to convert temperatures from
> and also Celsius to Fahrenheit or from Fahrenheit to Celsius and
> to print a range of temperatures that you want.
> */
> import javax.swing.*;
>
> public class TempConv
> {
> public static void main(String[] args)
> {
> String temp;
> int startTemp, endTemp, tempC, tempF, temp2;
> double temp1, degreesC, degreesF;
> char degrees;
>
> temp = JOptionPane.showInputDialog(
> "Enter any temperature (either Celsius or
> Farhenheit that you would like to convert");
> temp1 = Double.parseDouble(temp);
>
> degrees = JOptionPane.showInputDialog(
> "Enter C to convert Celsius or F
> Fahrenheit.");
>
> if ( (degrees == 'c') || (degrees == 'C') )
> {
> degreesF = temp1;
> degreesC = 5 * (degreesF - 32) /9;
> JOptionPane.showMessageDialog(null,
> degreesF + " Fahrenheit = "
> + degreesC + " Celsius");
> }
> else if ( (degrees == 'f') ||
> (degrees == 'F') )
> {
> degreesC = temp1;
> degreesF = ( 9 *
> (degreesC) / 5 ) + 32;
> JOptionPane.showMessageDialog
> (null,
> degreesC + " Celsius
> = " + degreesF + " Fahrenheit.");
> }
>
> else
> {
> degrees =
> JOptionPane.showInputDialog(
> "Enter either C to
> convert to Celsius or F to convert to Fahrenheit");
> }
>
> startTemp = JOptionPane.showInputDialog(
> "Enter a whole number starting
> tempterature.");
>
> endTemp = JOptionPane.showInputDialog(
> "Enter a whole number ending temperature
> higher than the starting temperature.");
>
> degrees = JOptionPane.showInputDialog(
> "To convert to Celsius enter C and to
> convert to Fahrenheit enter F");
> temp2 = startTemp;
>
> if ( ( (temp2 <= endTemp) && ( (degrees == 'c') ||
> (degrees == 'C') ) ) )
> {
> tempC = 5 * ( temp2 - 32 ) / 9;
> JOptionPane.showMessageDialog(null,
> temp2 + " F = " + tempC + " C \n");
> temp2++;
> }
> else if ( ( (temp2 <= endTemp) && ( (degrees == 'f')
> || (degrees == 'F') ) ) )
> {
> tempF = ( 9 * (temp2) / 5) + 32;
> JOptionPane.showMessageDialog(null,
> temp2 + " C = " + tempF + " F \n");
> temp2++;
> }
> else if (temp2 > endTemp)
> {
> temp2 = temp2 - endTemp;
> startTemp = JOptionPane.showInputDialog(
> "Your starting temperature is: " +
> temp2 + "above your ending temperature. \n" +
> "Please choose another number lower
> than: " + endTemp);
> }
> else
> {
> degrees = JOptionPane.showInputDialog(
> "Please enter either C to convert to Celsius
> or F to convert to Fahrenheit.");
> }
>
> }
> }
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/5cFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To reply to this message, go to:
http://groups.yahoo.com/group/beginnersclub/post?act=reply&messageNum=5468
Please do not reply to this message via email. More information here:
http://help.yahoo.com/help/us/groups/messages/messages-23.html
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/beginnersclub/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/