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.

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

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

Stuart

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

So, are you going to show us the code? M2

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

Ask Your Question

Weekly Poll

When do you think most people will be driving electric cars?

Discuss in The Lounge

Poll History