-6

I need to convert Fahrenheit to Celsius in a Java program with methods, a for loop statement, and no user input. It is supposed to display Fahrenheit temperatures 0 through 20 and it's Celsius conversions. Any solutions?

import java.util.Scanner;

public class celsiusTempTable
{
public static void main(String[] args)
{
      System.out.println("Fahrenheit to Celsius Conversion Table");
    double tempC = celsiusConversion(tempC);
      int tempF = fahrenheit(tempF);
    displayData(tempF, tempC);
}
    public static int fahrenheit(int F)
    {
       for(F = 0; F <= 20; F++)
       {
          return F;
       }
    }
    public static double celsiusConversion(double C)
{
        Scanner input = new Scanner(System.in);
        for(int F = 0; F <= 20; F++)
    {
    C = (5.0/9.0) * (F - 32);
    return C;
    }
}
public static void displayData(int F, double C)
{
        for(F = 0; F <= 20; F++)
    {
      System.out.println("\nThe temperature in Fahrenheit is: " + F);
      System.out.println("The temperature in Celsius is: " + C);
        }
}

}
damienfrancois
  • 52,978
  • 9
  • 96
  • 110
  • 6
    You'll learn a lot more if you do your own homework. I'd suggest starting by paying attention to formatting/indentation. – pjs Nov 16 '13 at 18:21
  • are you sure you don't want it the other way around `0°C` to `20°C` and their corresponding `F°`? – A4L Nov 16 '13 at 18:25
  • Maybe contact this person http://stackoverflow.com/questions/6806568/error-celsius-cannot-be-resolved-to-a-variable?rq=1 who is doing the same homework question. – Peter_James Nov 16 '13 at 18:26
  • Why are you using a loop inside your methods? Makes no sense. And why are you declaring scanner inside your method? – Paul Samsotha Nov 16 '13 at 18:27

2 Answers2

3

I'll only give hints.

  1. Without user input. So forget about using a Scanner and System.in.
  2. You need to understand what method arguments and method return values are. Arguments are usually the inputs of a method. And the return value is the output of the method. You're being asked to translate a temperature in fahrenheit degrees to a temperature in celsius degrees. This is a perfect situation where a method is useful. The input of the translation method is thus a unique integer value (the temperature in fahrenheit degrees), and the output is another single integer value (the temperature in celsius degrees).
  3. You must do that 21 times. Once with 0 as input, once with 1 as input, etc. until 20. This means you need a loop, and that at each iteration, you will translate the current temperature (0, 1, 2, etc.) into celsius degrees by calling the translation method, and print the result. Read your text book about for loops. This part should be in the main method.
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0

A quick search and have found the following:

Community
  • 1
  • 1
Peter_James
  • 647
  • 4
  • 14
  • 1
    (btw, the second one is a link to this specific question) – Dennis Meng Nov 16 '13 at 18:31
  • @DennisMeng Haha, I was going to post it in all of the above. Just seemed like a collection of students have the same HashTag at the moment. I guess classes have began. – Peter_James Nov 16 '13 at 18:32