1. Member
Join Date
Oct 2011
Posts
22
Rep Power
0

## methods... SO confused!

I have to write a methods program to calculate celsius and i am so lost. can anyone please help me? I keep getting "cannot find symbol" errors.

public class FahrenheitToCelsius {

public static void main(String[] args)
{
float fahrenheit, celsius;
String input;
celsius = calculateCelsius(fahrenheit);

input = JOptionPane.showInputDialog("Enter the Fahrenheit temperature you wish to convert as a floating point number.");
//Convert the input to float.
fahrenheit = Float.parseFloat(input);
}

//Calculate Celsius
public static float calculateCelsius(float f)
{
float celsius, fahrenheit;

celsius = calculateCelsius(fahrenheit);
return(5/9) * (fahrenheit-32);

2. Senior Member
Join Date
Jul 2011
Location
Melbourne, Victoria, Australia
Posts
155
Rep Power
6

## Re: methods... SO confused!

If you look at your code, your giving celsius a value of calculateCelsius(fahrenheit). You need to look at the order you have things occuring and rearrange some stuff.

3. Member
Join Date
Oct 2011
Posts
22
Rep Power
0

## Re: methods... SO confused!

I'll be honest, I have no idea what you mean. Should that go under the calculatecelsius method? I am so new to Java and basically ready to pull my hair out.

4. Member
Join Date
Oct 2011
Posts
22
Rep Power
0

## Re: methods... SO confused!

I am getting so many errors it's not even funny. I don't have a clue how to change this.
Can anyone tell me why my input boxes aren't even coming up?

5. Senior Member
Join Date
Jul 2011
Location
Melbourne, Victoria, Australia
Posts
155
Rep Power
6

## Re: methods... SO confused!

You need to get your input BEFORE you call the calculateCelcius method.
Here:
Java Code:
```//get input
input = JOptionPane.showInputDialog("Enter the Fahrenheit temperature you wish to convert as a floating point number.");
//Convert the input to float.
fahrenheit = Float.parseFloat(input);

//call calculateCelcius
celsius = calculateCelsius(fahrenheit);```

6. Senior Member
Join Date
Jul 2011
Location
Melbourne, Victoria, Australia
Posts
155
Rep Power
6

## Re: methods... SO confused!

I think you need to do some reading: The Really Big Index

7. Member
Join Date
Oct 2011
Posts
22
Rep Power
0

## Re: methods... SO confused!

I actually have read that. I have been all over the net, read my chapter 4 times, watched the book videos and emailed my teacher. I just don't seem to get it. And all of the errors I get aren't seeming to help.

8. Senior Member
Join Date
Jul 2011
Location
Melbourne, Victoria, Australia
Posts
155
Rep Power
6

## Re: methods... SO confused!

The best thing to do is write what you want to do down:
1. Ask user to input temperature in Fahrenheit.
2. convert input to Celsius
3. Show user temperature in Celsius.

and now go through what you need to do this:
1. A float variable for Fahrenheit
2. A way to put user input into Fahrenheit variable
3. A method that returns a float that converts Fahrenheit to Celsius
4. Print the result
3.

9. ## Re: methods... SO confused!

Originally Posted by ertopp
I actually have read that. I have been all over the net, read my chapter 4 times, watched the book videos and emailed my teacher. I just don't seem to get it. And all of the errors I get aren't seeming to help.

10. Member
Join Date
Oct 2011
Posts
22
Rep Power
0

## Re: methods... SO confused!

I did make a separate post with the errors, thank you. and I am not whining. Just saying that I have read all of that material and it wasn't helpful. Thats why I came here. I was hoping someone could help me. I am not asking for the answer, I just want to understand better. I am not terrible with Java. Methods confuse me and I want to learn why things are the way they are.

11. Member
Join Date
Oct 2011
Posts
22
Rep Power
0

## Re: methods... SO confused!

I tweeked my program a bit and will copy what I have now. Does this not seem to match the algorithm you just posted? I am only asking because I feel like it makes sense to me, then I get a ton of errors on the public static float calculateCelsius line.

This is what I have:

Java Code:
```public class FahrenheitToCelsius {

public static void main(String[] args){
{
float fahrenheit, celsius;
String input;

input = JOptionPane.showInputDialog("Enter the Fahrenheit temperature you wish to convert as a floating point number.");
//Convert the input to float.
fahrenheit = Float.parseFloat(input);

celsius = calculateCelsius(fahrenheit);

celsius = JOptionPane.showMessageDialog(null, fahrenheit + " degrees fahrenheit =" + celsius + " degrees celsius");
}

//Calculate Celsius
public static float calculateCelsius(float fahrenheit)
{
celsius = (5/9) * (fahrenheit - 32);
return celsius;
}

}

}```
Last edited by Fubarable; 10-08-2011 at 04:36 AM. Reason: code tags added

12. ## Re: methods... SO confused!

Originally Posted by ertopp
I did make a separate post with the errors, thank you. and I am not whining. Just saying that I have read all of that material and it wasn't helpful. Thats why I came here. I was hoping someone could help me. I am not asking for the answer, I just want to understand better. I am not terrible with Java. Methods confuse me and I want to learn why things are the way they are.
Your problem is that you need to study more as that's the only way to clear the confusion. Serious, it will help. Now for your current problem, please post your error messages here to keep the discussion from being fragmented. You should show which line is causing which error and show the actual error message itself.

You will also want to change your style of programming. If you're finding your code is showing lots of errors, it means that you're adding code to bad code, something you should never do. Instead start with a simple program skeleton, be sure it compiles and then every time you add a new line or two of code, check that it compiles correctly before adding any more code. If it doesn't fix it first.

13. Member
Join Date
Oct 2011
Posts
22
Rep Power
0

## Re: methods... SO confused!

These are the errors:

line 28: ';' expected
public static float calculateCelsius(float fahrenheit)

line 28: '.class' expected
public static float calculateCelsius(float fahrenheit)

line 28: illegal start of expression
public static float calculateCelsius(float fahrenheit)

line 28: ';' expected
public static float calculateCelsius(float fahrenheit)

line 28: illegal start of expression
public static float calculateCelsius(float fahrenheit)

^

14. Member
Join Date
Oct 2011
Posts
22
Rep Power
0

## Re: methods... SO confused!

Ok I do study and am actually doing fairly well. I said methods confuse me. I take online courses so I basically teach myself. It's hard to teach yourself something you don't understand.

15. ## Re: methods... SO confused!

Check your curly braces. You've got some where you shouldn't. Your code formatting is bad, and this is preventing you from seeing your errors. Use one consistent formatting style, myself, I recommend the one true brace style, but you should use whichever your teachers recommend since they are the ones who absolutely must be able to easily understand your code.

So my assignment to you is this: go through your code, correct its formatting and check each and every brace. Get rid of extra unnecessary braces, and make sure that opening and closing braces match where they are supposed to match.

16. Member
Join Date
Oct 2011
Posts
22
Rep Power
0

## Re: methods... SO confused!

But I thought you were to have braces around the code in each method?

17. ## Re: methods... SO confused!

Originally Posted by ertopp
But I thought you were to have braces around the code in each method?
Again, you have an extra set of braces. Find them.

18. Member
Join Date
Oct 2011
Posts
22
Rep Power
0

## Re: methods... SO confused!

Also, when I change braces around I get this error:
line 40: reached end of file while parsing

I use the layout provided by my book so I didn't know it was that bad.

19. ## Re: methods... SO confused!

Look carefully here:

Java Code:
```  public static void main(String[] args){
{
float fahrenheit, celsius;
String input;```
See anything extra?

20. Member
Join Date
Oct 2011
Posts
22
Rep Power
0

## Re: methods... SO confused!

yes, i do now. sorry. I have been staring at this program for hours.

Page 1 of 2 12 Last

#### Posting Permissions

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