Implement the following integer methods:

a.Method celsius returns the Celsius equivalent of a Fahrenheit temperature, using the calculation
b. C = 5.0 / 9.0 * ( F - 32 );

c. Method fahrenheit returns the Fahrenheit equivalent of a Celsius temperature, using the calculation

d. F = 9.0 / 5.0 * C + 32;

e. Use the methods from parts (a) and (b) to write an application that enables the user either to enter a Fahrenheit temperature and display the Celsius equivalent or to enter a Celsius temperature and display the Fahrenheit equivalent.

i don't know how to start this one...

Edited by jsefraijeen: n/a

4
Contributors
7
Replies
8
Views
7 Years
Discussion Span

Well start out by defining a class and within that class defining the two methods described above, as a start. Then, in the main method, ask for input and convert it using those methods.

And please a more descriptive topic title
"Help" is kind of a completly useless topic title in this forum

start defining a class then you make a constructor and create a method...

``````import java.util.Scanner;

public class CelsiusAndFarenheits
{

public double inCelsius()

{
Scanner in = new Scanner(System.in);

System.out.print("Enter a Celsius Temperature :");
double farenheit = in.nextDouble();
double F = 9.0 / 5.0 * farenheit + 32;
return F;

}

public double inFarenheit()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a Farenheit Temperator :");
double celsius = in.nextDouble();
double C = 5.0 / 9.0 * ( celsius - 32);
return C;
}

}``````
``````import java.util.Scanner;

public class CelsiusAndFarenheitsTest
{

public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
CelsiusAndFarenheits cf = new CelsiusAndFarenheits();
char choice;

System.out.print("Enter Temp Gauge [C]celsius/[F]farenheit:");
choice = in.next().charAt(0);

if(choice == 'C' || choice == 'c' )
{

double fh = cf.inCelsius();
System.out.print("In Farenheit is "+ fh);

}

else
{

double cl = cf.inFarenheit();
System.out.print("in Celsius is "+ cl);
}
}
}``````

like this?

Does it work?

Does it meet the requirements as listed?