Articles

Java Temperature Converter

August 11, 2005 at 03:21:30
Specs: Win XP, AMD Athlon XP - 1Gb RAM

Hi,
I've worked on doing an application in java to convert celsius to fahrenheit and visa-versa but it's not compiling and i can't seem to solve the errors. If anyone has a chance to take a look here's the code:
It comes in 2 parts.. 1 class with the equation and 1 class to control the user input:
1st Class:


import javax.swing.*;
import java.lang.*;
import java.io.*;
import java.util.*;

public class Equation {

public static float convertF(float temp)

{ fahrenheit = (centigrade*1.8f) + 32; }

public static float convertC(float temp)

{ centigrade = (fahrenheit/32)/1.8f; }
}


2nd Class:

import javax.swing.*;
import java.lang.*;
import java.io.*;
import java.util.*;

public class Temperature {

String input = JOptionPane.showInputDialog(null, "Enter which temperature you wish to convert using C or F:");
String temp = String.parseString(input);
{

if(temp.equals("C"));

String input1 = JOptionPane.showInputDialog(null, "Enter Temperature in Centigrade to convert:");
float centigrade = Equation.convertF(input1);

{

if(temp.equals("F"));

String input2 = JOptionPane.showInputDialog(null, "Enter Temperature in Fahrenheit to convert:");
float fahrenheit = Equation.convertC(input2);
}
}
}


Thanks if anyone can spot my errors.

Chris.


See More: Java Temperature Converter

Report •


#1
August 11, 2005 at 07:02:56

I'm not familiar with Java but you Fahrenheit to centigrade formula is wrong.

It should be:

centigrade = (Fahrenheit-32)/1.8f; }

Stuart


Report •

#2
August 11, 2005 at 08:55:54

ye thanks i've managed to redo the application from scratch and it's now working. Thanks a lot for your help.

Report •

#3
August 11, 2005 at 23:08:17

So, are you going to show us the code?

M2
If at first you don't succeed, you're about average.


Report •

Related Solutions


Ask Question