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 5 Years Ago by jsefraijeen: n/a

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

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?

Yup its working , but the im not sure if the outputs are correct because i don't know how to convert Celsius to Farenheit / Farenheit to Celsius.. :D

This article has been dead for over six months. Start a new discussion instead.