0

I'm trying to call a method from outside of the main method and I'm stumped on how to go about doing it. I may be going about this the wrong way. For instance, I'd like the user to enter in a temperature in Fahrenheit and then call the fahrenheitToCelsius method to do the conversion and return the converted temperature.

Here is what I have so far:

import java.util.Scanner;

public class Converter {

// conversions
private static final double GRAMS_PER_OUNCE = 28.3495;
private static final double CENTIMETERS_PER_FEET = 30.48;

public static double fahrenheitToCelsius (double f) {

    return (f - 32) / 1.8;
}

public static double feetToCentimeters (double feet) {

    return feet * CENTIMETERS_PER_FEET;
}

public static double ouncesToGrams (double ounces) {

    return ounces * GRAMS_PER_OUNCE;
}

public static void main(String[] args) {

    Scanner in = new Scanner(System.in);

    System.out.println("Enter a number in Fahrenheit: ");
    System.out.print(in.nextDouble());

}
}

1 Answers1

1
public static void main(String[] args) {

   Scanner in = new Scanner(System.in);

   System.out.println("Enter a number in Fahrenheit: ");
   double far = in.nextDouble();
   double cel = fahrenheitToCelsius (far); 
   System.out.println (cel); 
}

Like this?

Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
Kattie.S
  • 117
  • 1
  • 11