Reputation: 1
I'm having a problem with line 20 and I'm hoping someone can point me in the right direction as to what I'm doing wrong. All I'm trying to do is display a a display of Celsius along with their respective Fahrenheit temperatures. Celsius increments from 0-100 and Fahrenheit from 32 - 212. This is otherwise far from finished and I'm aware it's still a mess. I've gotten the data to to display but it's in one column as opposed to the two it's supposed to be in.
I appreciate your thoughts and input on this.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package celsiustofarenheittable;
/**
*
* @author these
*/
public class CelsiusToFarenheitTable {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
double celsiusToFarenheit,farenheit,celsius = 0;
celsiusToFarenheit = celsiusToFarenheit(farenheit,celsius); // HERE!
System.out.printf("Celsius \t Farenheit \n", celsius,farenheit);
{
for (celsius = 0; celsius <= 100; celsius += 10)
{
if (celsius <= 100 )
System.out.println(celsius);
}
while (farenheit <= 100){
System.out.println(farenheit * 1.8 + 32);
farenheit = farenheit + 10;
}
}
}
public static double celsiusToFarenheit(int celsius)
{
double farenheit;
farenheit = math.round(celsius * 1.8 + 32);
return farenheit;
}
}
Upvotes: 0
Views: 679
Reputation: 49
There is so many unnecessary variables and other stuffs that you don't really need. I have modified your code, made it as simple as possible, enjoy:
public class CelsiusToFarenheitTable {
public static void main(String[] args)
{
double fahrenheit = 32.0, celsius = 0.0;
System.out.printf("Celsius \t Farenheit \n", celsius,fahrenheit);
for (celsius = 10; celsius <=100; celsius+=10)
{
System.out.print(celsius);
System.out.print("\t");
System.out.println(celsius * 1.8 + 32);
fahrenheit = fahrenheit + 10;
}
}
}
Upvotes: 0
Reputation: 91
The celsiusToFarenheit
method is expecting one integer
parameter and you are providing two double
arguments in the line 20.
My suggestion is to make your celsius variable match the method argument type (int
), and provide just the celsius variable in the line 20:
celsiusToFarenheit(celsius)
Upvotes: 0
Reputation: 5021
You are really close, the actual conversion from Celsius to Fahrenheit is correct.
So your issue is that you are passing two doubles
, farenheit
and celsius
to your method celsiusToFarenheit(int celsius)
As you can see from the method declaration, it requires just int celsius
. From this celsius value you are doing the conversion to Fahrenheit.
So for instance:
int celsius = 10;
double fahrenheit = celsiusToFarenheit(celsius);
This produces a fahrenheit of 50, which is as to be expected
Upvotes: 2