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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 40

Thread: help with this code please!!!

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post help with this code please!!!

    Write a class that contains the following two methods:

    /** Converts from Celsius to Fahrenheit */

    Hello there guys please I need help with this program in java
    this what i have done so far , please any help would much appreciated
    Thanks.


    < public class EX5_8{
    public static void main(String args[]){
    /* 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.0) * fahrenheit + 32;
    }*/
    System.out.println("|Celsius |Fahrenheit||Celsius |Fahrenheit| \n");
    int i=40;
    int j=120;
    do{
    System.out.printf("%3.1f|%11.1f|%3.1f|%8.2f|\n",i, (i*(9.0/5)+32),j,(j/i*(5.0/9)-32));
    i-=1;
    j-=10;
    }while(i<=31 && j<=30);
    }
    }
    >

    Find below is the complete question

    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 methods to display the following tables:
    Celsius Fahrenheit Fahrenheit Celsius
    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

    Edit / Delete
    Last edited by fon90; March 31st, 2013 at 10:48 AM. Reason: systems administrators' requirement


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    Did you have any specific questions?

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    Yes please I just can get the program to print out the values it compiles
    but is not working

    This is the original question
    Find below is the complete question

    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 methods to display the following tables:
    Celsius Fahrenheit Fahrenheit Celsius
    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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    but is not working
    Can you describe what "not working" means?

    Post your code and the program's output and add some comments saying what is wrong with the output.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    I just want to be able to fit in the those methods in the program and make it work
    now is saying [Exception in thread ] "main" illegalformatConversionException

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    illegalformatConversionException
    Please copy the full text of the error message and post it here.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    Now is working without me uisng those methods < 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.0) * fahrenheit + 32;
    }>
    and am getting a wrong value for celsius column 4
    please .....I have tried to paste it here but it does not paste I don't know why sir..

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    it does not paste
    sorry, I don't know what your problem is. Most others are able to paste things here. How were you able to paste the code in post#1?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    Find below is my exact out put right now ....


    |Celsius |Fahrenheit||Celsius |Fahrenheit|

    40.0| 104.0|120.0| 184.00|
    Press any key to continue . . .

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    Do you have a question or comment about the output you posted?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    yes, it is suppose to print out like this...
    but I have not been able to make it work properly .

    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

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    Post the code in code tags and explain what is wrong with what the program prints out.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    [import java.util.Scanner;

    public class EX5_8{
    public static void main(String args[]){
    /* 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.0) * fahrenheit + 32;
    }*/
    System.out.println("|Celsius |Fahrenheit||Celsius |Fahrenheit| \n");
    double i=40;
    double j=120;
    do{
    System.out.printf(" %3.1f|%11.1f | %3.1f | %8.2f |\n",i,(i*(9.0/5)+32),j,j/(5.0/9.0)-32);
    i-=1;
    j-=10;
    }while(i<=31 && j<=30);
    }
    }][/QUOTE]
    The program do not print the right out put, and I don't know how to use the methods posted above in the program please guidance...

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    how to use the methods
    Here's a tutorial on how to use methods:
    http://docs.oracle.com/javase/tutori...arguments.html
    http://docs.oracle.com/javase/tutori...turnvalue.html
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    Hey cono if you wanna help you do that ,
    please al ready frustrated with this assignment and to be candid you are making things worst
    you keep asking same questions all over the place..
    i have showed you my code and where am @ .....
    so please if you have ideas direct and and if can't no problem
    my directed here thought I could get help
    Thanks.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    Your code is unformatted and hard to read. If you want help, you must format the code and wrap it in code tags.
    I do not work with unformatted code that is hard to read.
    When you format it, I will copy it and see what it does.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    please how do I format and wrap the code ,and code tag it? this is my first time using this forum

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    Please edit your post and wrap your code with code tags:
    [code=java] <<<< This goes before the code

    <YOUR CODE HERE>

    [/code] <<<< This goes after the code
    to get highlighting and preserve formatting.

    The formatted code will look like this:
          class TestGet<T> {
            public List<T> getList() {  // warning: [rawtypes] found raw type: List
                return null;
            }
           }
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    [code=java]
    [/import java.util.Scanner;

    public class EX5_8{
    public static void main(String args[]){
    /* 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.0) * fahrenheit + 32;
    }*/
    System.out.println("|Celsius |Fahrenheit||Celsius |Fahrenheit| \n");
    double i=40;
    double j=120;
    do{
    System.out.printf(" %3.1f|%11.1f | %3.1f | %8.2f |\n",i,(i*(9.0/5)+32),j,j/(5.0/9.0)-32);
    i-=1;
    j-=10;
    }while(i<=31 && j<=30);
    }
    }]
    </The code is here also import java.util.Scanner;

    public class EX5_8{
    public static void main(String args[]){
    /* 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.0) * fahrenheit + 32;
    }*/
    System.out.println("|Celsius |Fahrenheit||Celsius |Fahrenheit| \n");
    double i=40;
    double j=120;
    do{
    System.out.printf(" %3.1f|%11.1f | %3.1f | %8.2f |\n",i,(i*(9.0/5)+32),j,j/(5.0/9.0)-32);
    i-=1;
    j-=10;
    }while(i<=31 && j<=30);
    }
    }>

    --- Update ---

    <import java.util.Scanner;
     
    public class EX5_8{
    	public static void main(String args[]){
    	/*	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.0) * fahrenheit + 32;
    }*/
    			System.out.println("|Celsius |Fahrenheit||Celsius |Fahrenheit| \n");
    			double i=40;
    			double j=120;
    			do{
    				System.out.printf(" %3.1f|%11.1f |  %3.1f  | %8.2f |\n",i,(i*(9.0/5)+32),j,j/(5.0/9.0)-32);
    				i-=1;
    				j-=10;
    		    }while(i<=31 && j<=30);
    	}
    }>


    --- Update ---

    I formatted it well now
    find above is the code

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    }while(i<=31 && j<=30);
    This statement is false the first time the code is executed so the loop does not repeat.

    Add this line just before the above while to see what the values of i and j are:
               System.out.println("i="+i + ", j="+j);  //  print out values of i & j
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    ok, thanks but please how do include those methods in this program?

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    What methods? Please describe what they do and how they would be used in the program.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    In the original question of this assignment we are asked to use
    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.0) * fahrenheit + 32;
    }

    But if you look at my code i commented them because any I try to used them methods in my code I have tons of errors,please help me...

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with this code please!!!

    The names used in the methods are confusing: celsiusToFahrenheit() returns celsius. The name says it should return Fahrenheit.

    Have you tested the two methods to see if their conversions are correct?
    Call each with a value, print out what it returns and check that the conversion was done correctly.

    Don't forget to use code tags when posting code.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Junior Member
    Join Date
    Mar 2013
    Posts
    21
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with this code please!!!

    am sorry thats just me ..
    The question was include in your program
    <public static double fahrenheitToCelsisu(double celsius) / /converts from CToF
    public static double celsiusToFahrenheit(double fahrenheit) / /converts fromFToC>


    --- Update ---

    The want us to include those methods in the program

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 4
    Last Post: January 24th, 2013, 11:20 AM
  2. Replies: 7
    Last Post: January 24th, 2013, 10:41 AM
  3. Trouble Porting my Java File Reading Code to Android Code
    By Gravity Games in forum Android Development
    Replies: 0
    Last Post: December 6th, 2012, 04:38 PM
  4. Replies: 5
    Last Post: November 14th, 2012, 10:47 AM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM

Tags for this Thread