I am making a program to convert one temperature to another temperature. In example, Fahrenheit to Celsius, Celsius to Fahrenheit, Celsius to kelvin, etc.
I've got the GUI set up, but now i'm getting errors during conversion. I've looked for conversion methods, but can't seem to find any. So i'm writing them based on formulas i've seen online.
private static class EventHandler implements ActionListener {
/**
* this method gets called when an object we are listening to is interacted with
*
* @param evt ActionEvent that interacted with
*/
public void actionPerformed(ActionEvent evt) {
//creates the formating we would like for the numbers
DecimalFormat df = new DecimalFormat("#.##");
//if the event triggered was celInput than
if (evt.getSource() == cText) {
String strcText = cText.getText();
double cTemp = Double.parseDouble(strcText);
fText.setText("" + convertCtoF(cTemp));
kText.setText("" + convertCtoK(cTemp));
}else if(evt.getSource() == fText) {
String strfText = fText.getText();
double fTemp = Double.parseDouble(strfText);
cText.setText("" + convertFtoC(fTemp));
kText.setText("" + convertFtoK(fTemp));
}else if(evt.getSource() == kText) {
String strkText = kText.getText();
double kTemp = Double.parseDouble(strkText);
cText.setText("" + convertKtoC(kTemp));
fText.setText("" + convertKtoF(kTemp));
}
}//end actionPerformed method
}
public static double convertCtoF(double c) {
return (c / (5/9)) + 32;
}
public static double convertFtoC(double f) {
return (5/9) * (f - 32);
}
public static double convertCtoK(double c) {
return c + 273.15;
}
public static double convertFtoK(double f) {
return convertFtoC(f) + 273.15;
}
public static double convertKtoC(double k) {
return k - 273.15;
}
public static double convertKtoF(double k) {
return ((9/5) * convertKtoC(k)) + 32;
}
That's all the code I think would be necessary in order to find the logic error.
Any help would be greatly appreciated, as I cannot see why this is occurring.