• 0

[JAVA] Need a hint


Question

For my assignment i need to use 2 methods, getFahrentheit() and getCelsius() and this method has to convert the temp to Celsius before returning it. Fahrenheit to Celsius is (5 x (F-32)/9) Can anyone help on what to put in the getFahrenheit() and Celsius() methods?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Id do float, that way you can do the temp to decimal places. If your only

using whole numbers, do floats

class TemperatureConverter
{
 ?public static void main(java.lang.String[] args) 
 ?{
 ? ?TemperatureConverter tc = new TemperatureConverter();
 ?
 ? ? DecimalFormat df = new DecimalFormat("0.00");
 ? ? System.out.println(df.format(tc.getFahrenheit(50.5)); 
 ? ? System.out.println(df.format(tc.getCelsius(50.5));
 ? ?
 ? }

 ? public float getFahrenheit(float celsuisTemp) 
 ? {
 ? ? ?return //fahrenheit
 ? ?}
 ? 
 ? public float getCelsius(float fahrenheit)
 ?{
 ? ? ?return //celsius
 ? }
}

Edited by liykh001
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.