Convert temperatures in fahrenheit to celsius

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mbnumba14
    New Member
    • Nov 2008
    • 7

    Convert temperatures in fahrenheit to celsius

    Ok i need to create a java program that repeatedly read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered.

    My program is:
    [CODE=java]
    import java.util.*;
    // Converter.java
    public class Converter
    {
    public static void main(String[] args)
    {
    Scanner sc = new Scanner(System. in);
    System.out.prin t("Enter temp: ");
    int temp = sc.nextInt();
    System.out.prin tln(convertToC( temp));
    }
    public static int convertToC(int temp)
    {
    return ((temp - 32 ) * 5/9);
    }
    }
    [/CODE]

    I would really appreaciate it. Thank you. <email removed>
    Last edited by r035198x; Nov 14 '08, 07:14 AM. Reason: added code tags
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    What is your question?

    kind regards,

    Jos

    ps. use those [ code ] tags for readability reasons next time when you post code.

    Comment

    • mbnumba14
      New Member
      • Nov 2008
      • 7

      #3
      Originally posted by JosAH
      What is your question?

      kind regards,

      Jos

      ps. use those [ code ] tags for readability reasons next time when you post code.

      umm. my question is using the program that I have already posted, can you please modify that program so that it could read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered. Thank you very much for replying. Sorry about the code tags.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by mbnumba14
        umm. my question is using the program that I have already posted, can you please modify that program so that it could read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered. Thank you very much for replying. Sorry about the code tags.
        And what does your program do? Note that integer division does not do what
        people expect it to do.

        kind regards,

        Jos

        Comment

        • mbnumba14
          New Member
          • Nov 2008
          • 7

          #5
          ohh sorry, right now after a user inputs a number, the program outputs it in degrees Celcius.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by mbnumba14
            ohh sorry, right now after a user inputs a number, the program outputs it in degrees Celcius.
            Craft a liitle loop then and a small method that asks the user to enter a number
            in Fahrenheit degrees:

            Code:
            for (int f= getFahrenheit(); f <= 212; f= getFahrenheit())
               System.out.println(f+"F = "+convertToC(f)+"C");
            The convertToC() method converts Fahrenheit (its parameter) to Celcius.
            You already have that method.

            kind regards,

            Jos

            Comment

            • mbnumba14
              New Member
              • Nov 2008
              • 7

              #7
              yeah I know ,but ok. Maybe it would be easier for you to understand my question if it is wrote out like this:



              "Modify your main function in the Converter class to repeatedly read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered."

              Sorry about the confusion

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by mbnumba14
                yeah I know ,but ok. Maybe it would be easier for you to understand my question if it is wrote out like this:



                "Modify your main function in the Converter class to repeatedly read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered."

                Sorry about the confusion
                But I just told you how to do that ...

                kind regards,

                Jos

                Comment

                • mbnumba14
                  New Member
                  • Nov 2008
                  • 7

                  #9
                  oh, now I see it sorry about that. Not to sound stupid but, where would I insert that part you gave me at.

                  Comment

                  • mbnumba14
                    New Member
                    • Nov 2008
                    • 7

                    #10
                    wow thanks alot for the help. I really needed it. Thanks again

                    Comment

                    • mbnumba14
                      New Member
                      • Nov 2008
                      • 7

                      #11
                      Originally posted by JosAH
                      But I just told you how to do that ...

                      kind regards,

                      Jos
                      Once again I am sorry, but I am a begginner in Java programming. I tried to do what you told me but I have one error. Line 17 has the error message that reads [PHP]1 error

                      ----jGRASP wedge2: exit code for process is 1.[/PHP]

                      [PHP]import java.util.*;
                      // Converter.java
                      public class Converter
                      {
                      public static void main(String[] args)
                      {
                      Scanner sc = new Scanner(System. in);
                      System.out.prin t("Enter temp: ");
                      int temp = sc.nextInt();
                      System.out.prin tln(convertToC( temp));
                      }
                      public static int convertToC(int temp)
                      {
                      return ((temp - 32 ) * 5/9);
                      }
                      {
                      for (int f= getFahrenheit() ); f <= 212;
                      f= getFahrenheit() )
                      System.out.prin tln(f+"F = "+convertToC(f) +"C");
                      for (int f= getFahrenheit() ;
                      f <= 212; f= getFahrenheit() )
                      System.out.prin tln(f+"F = "+convertToC(f) +"C");
                      }
                      }[/PHP]

                      Comment

                      • JosAH
                        Recognized Expert MVP
                        • Mar 2007
                        • 11453

                        #12
                        Basically your program structure looks like this now:

                        Code:
                        public class Converter {
                        	public static void main(String[] args) { ... }
                         	public static int convertToC(int temp) { ... }
                         	{ /* some garbage statements ... */ }
                        }
                        That doesn't make sense does it? I had expected that loop I wrote for you
                        somewhere in the main method; not dangling at the end of the class, not in
                        any method at all. On top of that that bunch of statements contain quite a
                        lot of garbage as well.

                        kind regards,

                        Jos

                        Comment

                        Working...