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