# Conversions Between Celsius and Fahrenheit

• October 9th, 2011, 12:40 PM
baueml01
Conversions Between Celsius and Fahrenheit
Ok, I am trying to write code to convert both celsius to fahrenheit and fahrenheit to celsius. I have to use the two methods public static double celsiusToFahrenheit(double celsius) and public static fahrenheitToCelsius(double fahrenheit) in the code. I am really lost as to where I am supposed to go in my program. I will attach my program hoping someone can help me get through this. This is only my second programming class so you will have to bear with me as I am new. Thanks for the help!

//Michael Bauer Exercise 5.8
public class ConversionsBetweenCelsiusAndFahrenheit{
public static void main(String[] args){
for(double celsius=40; celsius<=31.0; celsius--){
System.out.print(celsiusToFahrenheit);
for(double fahrenheit=120; fahrenheit<=30.0; fahrenheit--){
System.out.print(fahrenheitToCelsius);
}
public static double celsiusToFahrenheit(double celsius){
double fahrenheit;
celsiusToFahrenheit=(5.0/9.0)*fahrenheit-32;
return fahrenheit;
}
public static double fahrenheitToCelsius(double fahrenheit){
double celsius;
fahrenheit=(9.0/5)*celsius+32;
return fahrenheitToCelsius;
}
}
• October 9th, 2011, 12:46 PM
copeg
Re: Conversions Between Celsius and Fahrenheit
What is the problem? We can guess - mine being you don't know how to call the methods (If so, see Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects) ) - but guesses are just that. Ask a specific question, get a specific answer. Suggested reading: http://www.javaprogrammingforums.com...-get-help.html
• October 9th, 2011, 04:21 PM
baueml01
Re: Conversions Between Celsius and Fahrenheit
//Michael Bauer Exercise 5.8
public class ConversionsBetweenCelsiusAndFahrenheit{
public static void main(String[] args){
for(double celsius=40; celsius<=31.0; celsius--){
System.out.print(celsiusToFahrenheit(fahrenheit));
for(double fahrenheit=120; fahrenheit<=30.0; fahrenheit--){
System.out.print(fahrenheitToCelsius(celsius));
}
public static double celsiusToFahrenheit(double celsius){
return celsius=(5.0/9.0) * fahrenheit - 32;
}
public static double fahrenheitToCelsius(double fahrenheit){
return fahrenheit=(9.0/5) * celsius + 32;
}
}
}
}

I figured out how to call on methods. When I say I need help I need all around help with the whole program. I am a junior in college and this is my second java programming class. My first one was about 6-7 months ago. I know I lack experience and knowledge! That is why I came to this website, hoping to get hopes from experiences people on how to help me complete this program. Basically I need to finish this program and be able to compile it and run it because I have one more to write tonight (that's even harder) before tomorrow.
• October 9th, 2011, 05:27 PM
copeg
Re: Conversions Between Celsius and Fahrenheit
You say you need to finish the program, but have yet to tell us what the requirements are. Without knowing the destination, we can't give you directions (and should we try to guess, can quite probably lead you in the wrong direction). Did you read the suggested reading link I posted above?
• October 9th, 2011, 05:49 PM
baueml01
Re: Conversions Between Celsius and Fahrenheit
ok here is the whole question in the book:

(Conversions between Celsius and Fahrenheit) Write a class that contains the following two methods:
//Converts from celsius to fahrenheit
public static double celsiusToFahrenheit(double celsius)

//Converts from fahrenheit to celsius
public static double fahrenheitToCelsius(double fahrenheit)

The formula for the conversion is:
fahrenheit=(9.0/5) * celsius + 32

Write a test program that invokes these two methods to display the following tables.
Celsius Fahrenheit Celsius Fahrenheit
40.0 104.0 120.0 48.89
39.0 102.2 110.0 43.33
.................................................. .......................
32.0 89.6 40.0 4.44
31.0 87.8 30.0 -1.11

This is the exact question from the book. I hope that it helps out
• October 9th, 2011, 05:51 PM
baueml01
Re: Conversions Between Celsius and Fahrenheit
What I have finished so far will not compile in cmd.
• October 9th, 2011, 07:49 PM
copeg
Re: Conversions Between Celsius and Fahrenheit
Quote:

Originally Posted by baueml01
What I have finished so far will not compile in cmd.

There are some syntax errors in the code you posted above, but I would first say to break the problem down. Concentrate on one requirement at a time. I would say strip out all code of the class, then build back up - take the first method to convert C to F
Code :

```public static double celsiusToFahrenheit(double celsius){ return celsius=(5.0/9.0) * fahrenheit - 32; }```

Where has fahrenheit been declared (the compiler must know what the variables are)? Further, you might want to check the formula for this. It oftentimes helps to write out on paper how you would accomplish this, then move that to code. Try writing this method only - without the other pieces of code. Make sure it compiles before moving forward. Post back if it does not