Computing.Net > Forums > Programming > Java Temperature Converter

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java Temperature Converter

Reply to Message Icon

Name: jarvio678
Date: August 11, 2005 at 03:21:30 Pacific
OS: Win XP
CPU/Ram: AMD Athlon XP - 1Gb RAM
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: August 11, 2005 at 07:02:56 Pacific
Reply:

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

It should be:

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

Stuart


0

Response Number 2
Name: jarvio678
Date: August 11, 2005 at 08:55:54 Pacific
Reply:

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


0

Response Number 3
Name: Mechanix2Go
Date: August 11, 2005 at 23:08:17 Pacific
Reply:

So, are you going to show us the code?

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Java Temperature Converter

Java Currency Converter Application www.computing.net/answers/programming/java-currency-converter-application/10198.html

Java-Cannot convert double to class www.computing.net/answers/programming/javacannot-convert-double-to-class/12172.html

C or Java or PERL www.computing.net/answers/programming/c-or-java-or-perl/12136.html