PDA

View Full Version : Celsius to Faherneit convertor starting at 90 degrees

tomwaits4noman
10-18-2009, 11:44 AM
Hi I am having problems with a college assignment

Its a celsius to Fahrenheit converter I have the first part working however the

second part of the project involves coding the converter to convert from 90 degrees celsius to 95 degrees celsius.

I figure the best way is through an if or else statement but I not sure how to work this into the code I have.

the third part of the project involves using decimal format when I try to run the decimal format the project fails.

The code for 90 degrees upwards is as follows

f=((9.0/5.0)*90)+32);

I guess I use an if or else statement

if 90

else 90<

like

if((int)((degree - 32) * 5)/9 == 90) {
System.out.println("194 degrees Fahrenheit");
} else if ((int)((194 - 32) * 5)/9 == <90 ) {
System.out.println(" degrees Fahrenheit" );
}

but not sure how to work this into the code

the code for the decimal format I have is

import java.text.Decimalformat;

DecimalFormat oneDigit = new
DecimalFormat ("0.0");

System.out.println("90"+ oneDigit.Format (f));

The following is for the code for the converter working as normal.

package converter;

import javax.swing.JOptionPane;

public class Converter {

public static void main(String[] args) {

String degreestring = JOptionPane.showInputDialog("Enter a temperature in degrees Celsius:");

int degree;
degree = Integer.parseInt( degreestring );

int fahrenheit;
fahrenheit = (int) ((9.0 / 5.0) * degree + 32.0);

JOptionPane.showMessageDialog(null, degree + " degrees Celsius = " + fahrenheit + " degress Fahrenheit");

System.exit(0);
}

}

Any help would be greatly appreciated. thanks

djr33
10-18-2009, 05:47 PM
I don't get why there is any difference in 90 and 95 degrees: both are numbers, and you can use the same equation to convert both. Just use a variable, do the math, and that's it.
Generally we encourage those doing homework assignments to figure it out themselves, because otherwise you're not learning what you have to for the course, if we just do it for you. But as I said, if you just approach this as a one step thing, it should be easy-- just use a variable and go from there. The different values can be determined by what value you set the variable to before the conversion.