Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help With Temperature Converter (Beginner).

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Location
    Dunedin, New Zealand
    Posts
    2
    My Mood
    Happy
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help With Temperature Converter (Beginner).

    Hi there.
    Am just starting out with java and am having trouble to get this code to work. Its one of my exercises in my course and I've been trying to find a way to get it to work for a bit now (knowing me it will be something obvious i have overlooked). I can't seem to get the variable celsius into the convert method in order to proceed. I have been playing around but what I've tried doesn't seem to complete compilation. Any ideas would be greatly appreciated.

    This is my first forum post and apologise in advance if formatting etc isn't correct.

    Thanks.

    import java.util.Scanner;
     
    public class FahrenheitToCelsius{
     
      public static void main(String[]args){
        convertFToC();
      }
      public static void convertFToC(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter Fahrenheit temperature");
        double fahrenheit = scan.nextDouble();
        System.out.println(fahrenheit + " degrees Fahrenheit is" + celsius + "degrees Celsius");
      }
      public static double toCelsius (double fahr){
        final int BASE = 32;
        final double CONVERSION_FACTOR = 9.0 / 5.0;
        final double CEL_CONVERSION_FACTOR = 5.0 / 9.0;
        double celsius = fahr * CEL_CONVERSION_FACTOR - BASE;
        return celsius;
     
      }
     
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help With Temperature Converter (Beginner).

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    At some point before the result is presented, you'd 'call' the toCelsius() method with the user's input:

    double celsius = toCelsius( fahrenheit );

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    regsterbear (July 23rd, 2014)

  4. #3
    Junior Member
    Join Date
    Jul 2014
    Location
    Dunedin, New Zealand
    Posts
    2
    My Mood
    Happy
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help With Temperature Converter (Beginner).

    Thanks for the help. Appreciate it a lot

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help With Temperature Converter (Beginner).

    You're welcome.

Similar Threads

  1. Converter
    By xdevilx3 in forum Java Theory & Questions
    Replies: 13
    Last Post: November 18th, 2013, 09:40 AM
  2. Temperature
    By Program83 in forum Loops & Control Statements
    Replies: 3
    Last Post: June 25th, 2013, 09:57 PM
  3. temperature converter
    By pranavk26 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 11th, 2013, 06:38 AM
  4. Temperature Converter Program is not running properly
    By jessieaugust in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 5th, 2013, 11:31 AM
  5. (Beginner) Hopelessly lost on Temperature converting (C to F, F to C)
    By skw4712 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: July 18th, 2011, 07:34 PM