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

1. ## 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

2. ## Re: help with this code please!!!

Did you have any specific questions?

[code=java]
[/code]
to get highlighting and preserve formatting.

3. ## 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. ## 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.

5. ## 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. ## Re: help with this code please!!!

illegalformatConversionException
Please copy the full text of the error message and post it here.

7. ## 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. ## 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?

9. ## 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. ## Re: help with this code please!!!

Do you have a question or comment about the output you posted?

11. ## 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. ## Re: help with this code please!!!

Post the code in code tags and explain what is wrong with what the program prints out.

13. ## 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. ## Re: help with this code please!!!

[code=java]
[/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

15. ## Re: help with this code please!!!

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. ## 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.

17. ## 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. ## Re: help with this code please!!!

[code=java] <<<< This goes before the code

[/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;
}
}```

19. ## 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. ## 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`

21. ## Re: help with this code please!!!

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

22. ## Re: help with this code please!!!

What methods? Please describe what they do and how they would be used in the program.

23. ## 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. ## 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.

25. ## 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 Last