1. Member
Join Date
Oct 2013
Posts
1
Rep Power
0

## Please Help D: converting temperature from Fahrenheit to Celsius program

Hey Guys-

Im very new to Java and have a program due tonight at 10. My program unfortunately is not compiling... could someone please look over it and give me some advice to fix it? The purpose of the program is to convert Fahrenheit to Celsius.

/*
*Filename: Temperatureconversion.java
*Created: 10/20/13 by Brittany Stevens
*
*Purpose: Convert temp from Fahrenheit to Celsius, user input
*/

import javax.Swing.JOptionPane;

public class Temperatureconversion
{

//main method
public static void main( String[] args)
{

/************************************************** ********************************
declare variables and initialize variables
************************************************** ********************************/

String openingMessage = "Welcome to the temperature conversion program",
idMessage = "Please enter temperature in Fahrenheit to nearest degree",
outputMessage,
tempF,
tempFStr,
tempC,

/************************************************** ********************************
input
************************************************** ********************************/
tempFStr = JOptionPane.showInputDialog( tempF );

/************************************************** ********************************
processing
************************************************** ********************************/
tempF = Integer.parseInt(

// calculate celsius temperature
tempC = ( tempF - 32) * 5/9;

/************************************************** ********************************
output
************************************************** ********************************/
outputMessage = "The Fahrenheit temperature of " + tempF " equals a Celsius temperature of " + tempC,

JOptionPane.showMessageDialog( null, outputMessage );

System.exit(0);

} // end main

} // end class

2. Member
Join Date
Oct 2013
Posts
15
Rep Power
0

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Hello Dredgge/Brittany,

First how are you compiling? If you are using an IDE such as Netbeans (for example) it should show you all your compiling errors in the "Debug" feature. You may not be familar with this feature since it seems you are in a basic programming class and may not even be using that IDE. It's a great feature and worth learning, unfortuantely it would take me a very long time to explain it through here with screen shots so if you have Netbeans, google it or ask someone to show you.

Here is what I did real quick to see what errors you ran in to. I just copied your code, vim'ed a file named "help.java", and ran this in my terminal. I use Linux but you can accomplish the same thing in Windows with the cmd.exe you type in the run prompt:

\$ javac help.java
which produced these results

help.java:42: error: ')' expected
tempC = ( tempF - 32) * 5/9;
^
help.java:49: error: ';' expected
outputMessage = "The Fahrenheit temperature of " + tempF " equals a Celsius temperature of " + tempC,
^
help.java:49: error: not a statement
outputMessage = "The Fahrenheit temperature of " + tempF " equals a Celsius temperature of " + tempC,
^
help.java:49: error: ';' expected
outputMessage = "The Fahrenheit temperature of " + tempF " equals a Celsius temperature of " + tempC,
^
4 errors
Now I have somewhere to work from.

Had you done something like this and posted it, the members here would have had a much easier time helping you. Personally and I think I can speak for many people, the last thing we want to do is trace through your code line by line and hunt for compiling errors. I'm not saying this to be mean, just to illustrate a point and make it so you can help others help you effectively.

With that said I can now look into why your code is not compiling.

Your first mistake is here:

Java Code:
```30 tempF = Integer.parseInt(
40
41 // calculate celsius temperature
42 tempC = ( tempF - 32) * 5/9;```

From the consel output "help.java:42: error: ')' expected" I knew there would be an error around the 42 line. It's on 39 where you forgot to close your method bracket ")" and the ";". Line 39 in my example should read:

Java Code:
`39 tempF = Integer.parseInt();`
Second mistake is multiple mistakes in one:

Java Code:
`49 outputMessage = "The Fahrenheit temperature of " + tempF " equals a Celsius temperature of " + tempC,`

Java Code:
`49 outputMessage = "The Fahrenheit temperature of " + tempF  + " equals a Celsius temperature of " + tempC;`
You missed the concatenation operator "+" and had a "," instead of the ";" to terminate the line.

After that I thought that it would just be the fact your tempF is an integer and your tempC is a float so type String mismatches, but then I thought Java just handles strings so I tried a compile again, here's what I got:

\$ javac Temperatureconversion.java
Temperatureconversion.java:8: error: package javax.Swing does not exist
import javax.Swing.JOptionPane;
^
Temperatureconversion.java:33: error: variable tempFStr is already defined in method main(String[])
tempFStr = JOptionPane.showInputDialog( tempF );
^
Temperatureconversion.java:33: error: cannot find symbol
tempFStr = JOptionPane.showInputDialog( tempF );
^
symbol: variable JOptionPane
location: class Temperatureconversion
Temperatureconversion.java:39: error: no suitable method found for parseInt()
tempF = Integer.parseInt();
^
method Integer.parseInt(String) is not applicable
(actual and formal argument lists differ in length)
method Integer.parseInt(String,int) is not applicable
(actual and formal argument lists differ in length)
Temperatureconversion.java:42: error: bad operand types for binary operator '-'
tempC = ( tempF - 32) * 5/9;
^
first type: String
second type: int
Temperatureconversion.java:51: error: cannot find symbol
JOptionPane.showMessageDialog( null, outputMessage );
^
symbol: variable JOptionPane
location: class Temperatureconversion
6 errors
Damn..... So now I have to figure these out and trouble shoot them one at a time....

Ok then. The first one is easy:

Temperatureconversion.java:8: error: package javax.Swing does not exist
import javax.Swing.JOptionPane;

Java Code:
`8 import javax.Swing.JOptionPane;`
And should read this:

Java Code:
`8 import javax.swing.JOptionPane;`
You accidentally capitolized the "S" in swing. Easy fix

Now compile again:

\$ javac Temperatureconversion.java
Temperatureconversion.java:33: error: variable tempFStr is already defined in method main(String[])
tempFStr = JOptionPane.showInputDialog( tempF );
^
Temperatureconversion.java:39: error: no suitable method found for parseInt()
tempF = Integer.parseInt();
^
method Integer.parseInt(String) is not applicable
(actual and formal argument lists differ in length)
method Integer.parseInt(String,int) is not applicable
(actual and formal argument lists differ in length)
Temperatureconversion.java:42: error: bad operand types for binary operator '-'
tempC = ( tempF - 32) * 5/9;
^
first type: String
second type: int
3 errors
Ah, much better. Only 3 errors. Alright so I think I have illustrated my step by step problem solving method so for the rest I'll just show you quickly. You should try to step through the errors in your code like this always and then when you hit a problem you just can't solve, post that on a forum like this.

Alright here is the quick sort of dirty fix (dirty meaning there are somethings I don't like about your code that I personally would be picky about and if in person could sit down and explain it over a period of time, which isn't really reasonable on the computer. Also do not take this as me saying your code is bad, it's just I prefer certain things).

First it was your variables I fixed. You had this:

Java Code:
```String openingMessage = "Welcome to the temperature conversion program",
idMessage = "Please enter temperature in Fahrenheit to nearest degree",
outputMessage,
tempF,
tempFStr,
tempC,

/************************************************** ********************************
input
************************************************** ********************************/
tempFStr = JOptionPane.showInputDialog( tempF );```
I'm guessing your professor does that "," way of defining multiple variables. While this is normally fine, I don't prefer it because stuff like this happens and I think it's less readale but I'll go ahead and show you that way. You had everything as a string, defined tempFStr twice, and tried to pass the tempF as the InputDialog string which I'm guessing you wanted to pass idMessage. I fixed this by grouping your Strings together, defining the integer and float, and defining tempFStr once. Also I took the liberty of using your openingMessage string since you didn't use it anywhere and added it to the jOptionPane():

Java Code:
``` 23 String openingMessage = "Welcome to the temperature conversion program",
24 idMessage = "Please enter temperature in Fahrenheit to nearest degree",
25 outputMessage,
26 tempFStr;
27 int tempF = 0;
28 float tempC = 0F;
29
30 /************************************************** ********************************
31 input
32 ************************************************** ********************************/
33 tempFStr = JOptionPane.showInputDialog(openingMessage + "\n" + idMessage);```

Java Code:
`tempF = Integer.parseInt();`
The problem is that the method, Integer.parseInt(); , has no value to parse. I could have fixed this earlier but I wanted to show you that you can fix a syntax problem but still have a runtime problem that you won't find until you compile.

Java Code:
`tempF = Integer.parseInt(tempFStr);`
That should be it, but it's possible I forgot to transcribe something to you since this is a long message. Please go through and fix all your code according to what I have written and see if you can get it to compile. Once you do this post back here your code that compiles. If you get stuck, post your errors that you are getting and/or questions.

Hope this helps.

3. Member
Join Date
Oct 2013
Posts
15
Rep Power
0

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Haha, guess I wrote all that for nothing. Oh well it was fun fixing your code, thanks

4. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
13

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

People are on different timezones you know, you should be a little more patient.

But you should know that spoonfeeding code to people helps nobody; you should aim to guide people to help them fix stuff themselves so they may learn something along the way, not do all the work for them.

5. Member
Join Date
Oct 2013
Posts
15
Rep Power
0

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Originally Posted by gimbal2
People are on different timezones you know, you should be a little more patient.

But you should know that spoonfeeding code to people helps nobody; you should aim to guide people to help them fix stuff themselves so they may learn something along the way, not do all the work for them.
First, I waited until well after my post and her project was due before I sent my joking sarcasm . My first post (which is the help post): 10-21-2013, 09:53 AM. My second post: 10-23-2013, 02:15 PM. I guess 48+ hours is still not long enough to post back giving her a hard time when she said this, "Im very new to Java and have a program due tonight at 10". Clearly you couldn't tell I was joking.

Now I do have to respond to your absurd accusation of spoonfeeding code. I wrote my problem solving methodology and how I would tackle each individual problem and then showed how I would fix each of those problems. She wrote all the code and I just pointed out her mistakes and showed the fixes. She would have to write in all the code herself or at least copy/paste everything and then compile and she would have to read each thing I wrote to know where it goes and why.

Have you ever helped anyone or tutored anyone before? Or did you just not bother to read my post and just assumed I spoonfed code? There is a clear difference, it just seems you are unable to discern that difference.

6. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
13

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Have you ever helped anyone or tutored anyone before?
Probably more than you, sad misguided person.

7. Member
Join Date
Oct 2013
Posts
15
Rep Power
0

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Originally Posted by gimbal2
Probably more than you, sad misguided person.
From your responses that is clearly not true.

8. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
27

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Originally Posted by histamineblkr
From your responses that is clearly not true.
You said it yourself, all they would have to do is copy/paste.
That's not learning.
They don't even have to figure out where to paste to as you explained exactly where.

The point is the original poster did not post the problems they were having.
One of the things they need to learn is how to ask their questions. Simply posting code and going "this doesn't work" is not a Good Thing. So they need to describe (in detail) the problem. In this case the compilation errors. That way we can explain, an error at a time, what that problem is...or even better get them to figure it out for themselves.

The first import statement is something that simply needed answering with a "Java is case sensitive" comment, for example.

9. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Although it can be somewhat subjective, you were spoon feeding.

Oh well it was fun fixing your code
From what I have seen on this forum it is okay to point out the occasional syntax problem. Or to provide code if you are explaining a concept about Java (or if you have told them something wrong and need to correct it). But don't correct all their errors for them. Just having them fix them or research why some code you pointed out is incorrect will be of much more help to them.

Regards,
Jim

10. Member
Join Date
Oct 2013
Posts
15
Rep Power
0

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Originally Posted by jim829
Although it can be somewhat subjective, you were spoon feeding.

From what I have seen on this forum it is okay to point out the occasional syntax problem. Or to provide code if you are explaining a concept about Java (or if you told them something wrong and need to correct it). But don't correct all their errors for them. Just having them fix them or research why some code you pointed out is incorrect will be of much more help to them.

Regards,
Jim
Originally Posted by Tolls
You said it yourself, all they would have to do is copy/paste.
That's not learning.
They don't even have to figure out where to paste to as you explained exactly where.

The point is the original poster did not post the problems they were having.
One of the things they need to learn is how to ask their questions. Simply posting code and going "this doesn't work" is not a Good Thing. So they need to describe (in detail) the problem. In this case the compilation errors. That way we can explain, an error at a time, what that problem is...or even better get them to figure it out for themselves.

The first import statement is something that simply needed answering with a "Java is case sensitive" comment, for example.
I can see where both of you are coming from and perhaps there is some validity and value to providing the type of help you are describing. However, I don't feel it is the best approach.

Had I just fixed her code and posted the correct code, that would be what you are both likening to what I did. That would not be helpful and would not help anyone.

Here is why I did what I did. I saw multiple reasons that my step by step approach would be beneficial to a person's learning.

First is I remember how confusing my first programs were. People just telling me to go search Google, vague help that they think is clear, or unspecific help was not effective. What was effective was people explaining things in detail and why. This is what I tried to do. I understand why it can be confused as just "spoon feeding". As beginners, people need thorough explanations, examples, and need to be shown how. You don't hand someone a wrench, tell them "righty tighty, lefty Lucy." and expect them to tear down, rebuild, and port and polish an engine.

Second is for anyone in the future who has this same project. If the come here and read through my response the will gain some insight on how to spot mistakes in their own code and how to troubleshoot on the command line.

I am fine with either of you disagreeing with me and thinking I did too much. When I tutored math and computer science daily at my college for a few years, I found the most helpful thing for students was very detailed and thorough explanations initially. As they grasped the concepts and became more comfortable you would give them less and less until they fully developed their problem solving skills and only needed occasional help.

Anyway, I have now explained my approach and why. Perhaps it will make sense to either of you or you may still think what I did was not helpful.

11. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
27

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

The point is (and this is from experience) they don't go through the long spiel if highlighted in that spiel is the answer they're looking for, in nice copy/paste chunks. That's what we're trying to avoid here. Having worked with people who clearly got through whatever training they did by copy/paste I really don't want to encourage it.

12. Member
Join Date
Oct 2013
Posts
15
Rep Power
0

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Originally Posted by Tolls
The point is (and this is from experience) they don't go through the long spiel if highlighted in that spiel is the answer they're looking for, in nice copy/paste chunks. That's what we're trying to avoid here. Having worked with people who clearly got through whatever training they did by copy/paste I really don't want to encourage it.
Ok I understand what you are saying. I didn't think she would be able to pick out the pieces of code and change it without actually reading through my post, but at least I learned what not to do.

So had I gone through, pointed out the mistakes, and gave no fixes would that have been acceptable?

13. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

[QUOTE=histamineblkr;360321
So had I gone through, pointed out the mistakes, and gave no fixes would that have been acceptable?[/QUOTE]

IMO, it would have been better for sure. I have done just that from time to time. Sometimes the OP's just don't get it no matter what. So a little spoon feeding might jump start their brain. Or you can demonstrate a concept using code and then let them figure out how to apply it to their own situation. I struggle sometimes with whether I have spoon fed someone too much. Like I said, it is very subjective. And it is hard for me to be consistent over hundreds of posts. Usually, pointing out some syntax errors and let them fix it is not that bad. Solving their problem for them is certainly taboo.
Others may have a different take on this.

Regards,
Jim

14. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
27

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

For me I would have started by getting them to actually post the errors they were getting.
They need to get into the habit of reading and understanding the compilation messages, which includes realising that simply saying "it doesn't compile" is not all that helpful. Expecting us to copy and paste the code into an IDE to see what's wrong doesn't go down well with me.

And then, explain what each of the messages means.

15. Member
Join Date
Oct 2013
Posts
15
Rep Power
0

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Originally Posted by jim829
IMO, it would have been better for sure. I have done just that from time to time. Sometimes the OP's just don't get it no matter what. So a little spoon feeding might jump start their brain. Or you can demonstrate a concept using code and then let them figure out how to apply it to their own situation. I struggle sometimes with whether I have spoon fed someone too much. Like I said, it is very subjective. And it is hard for me to be consistent over hundreds of posts. Usually, pointing out some syntax errors and let them fix it is not that bad. Solving their problem for them is certainly taboo.
Others may have a different take on this.

Regards,
Jim
I knew how that last day crunch can be for a program that is due and that beginners often do not even know how to ask questions properly or what they should do to get the right help. I'll be sure to avoid the taboo aspect of solving for people. Thanks for the feedback.

16. Member
Join Date
Oct 2013
Posts
15
Rep Power
0

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Originally Posted by Tolls
For me I would have started by getting them to actually post the errors they were getting.
They need to get into the habit of reading and understanding the compilation messages, which includes realising that simply saying "it doesn't compile" is not all that helpful. Expecting us to copy and paste the code into an IDE to see what's wrong doesn't go down well with me.

And then, explain what each of the messages means.
I did say at the beginning of my post that she should try and use a debugging feature in a program like Netbeans and that she should post her errors so that she would be more likely to get some practical and specific help. I figured that it was the day before it was due and she was just stressing so I was a bit extra helpful. I will make sure not to help in that way a make the members work out their own problems as much as possible. Thank you for the feedback as well.

17. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
13

## Re: Please Help D: converting temperature from Fahrenheit to Celsius program

Originally Posted by histamineblkr
I will make sure not to do a disservice in that way a make the members work out their own problems as much as possible. Thank you for the feedback as well.
Small correction.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•