0

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
6 Years
Discussion Span
Last Post by masijade
Featured Replies
  • 1

    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. Read More

1

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.

0

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

0
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?

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.