Hi, I've been working on this project off and on. I am very close to completing in.

What it is is a program that calculates temperature from fahrenheit - centigrade - Kelvin. Please feel free to help.

Here's my code sorry for the length of it:

//-- Shaun D. --

//Started on 1/02/10

//-- PURPOSE: To convert Temperatures from F to C to K

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.lang.*;
import java.text.DecimalFormat;
import java.util.*;

//START OF TEMPCONVERSION CLASS

public class TempConversion extends JFrame
{
 	//Math constants start  
	private static int OFFSET = 32;
	private static double FTOC = 5/9;
	private static double CTOF = 9/5;
	private static int KOFFSET = 273; //Kelvin Offset
	private static int WIDTH = 700;
	private static int HEIGHT = 150;
	
	//TextFields Start
	private JTextField CentigradeTF;
	private JTextField FahrenheitTF;
	private JTextField KelvinTF;
	
	//Labels start
	private JLabel lblcent;
	private JLabel lblkelv;
	private JLabel lblfahr;
	
	//Decimal Formats
	DecimalFormat dfFahr = new DecimalFormat("#.##");
	DecimalFormat dfCent = new DecimalFormat("#.##");
	DecimalFormat dfKelv = new DecimalFormat("###.##");
	
	
	
   //Handlers start
	private CentHandler CentigradeHandler;
	private  FahrHandler FahrenheitHandler;
	private  KelvHandler KelvinHandler;
	
	public TempConversion()
	{
	   super("Temperature Conversion Program v. 1.0");
		Container c = getContentPane();
		
		c.setLayout(new GridLayout(5,8));
		
		lblfahr = new JLabel("Fahrenheit: ", SwingConstants.RIGHT);
		lblcent = new JLabel("Centigrade: ", SwingConstants.RIGHT);
		lblkelv = new JLabel("Kelvin: ", SwingConstants.RIGHT);
		
		FahrenheitTF = new JTextField(15);
		CentigradeTF = new JTextField(15);
		KelvinTF = new JTextField(15);
		
		 CentHandler CentigradeHandler  = new CentHandler();
		 FahrHandler FahrenheitHandler = new FahrHandler();
		 KelvHandler KelvinHandler  = new KelvHandler();
		
		FahrenheitTF.addActionListener(FahrenheitHandler);
		CentigradeTF.addActionListener(CentigradeHandler);
		KelvinTF.addActionListener(KelvinHandler);
	
		//Add Components to Container
		c.add(lblfahr);
		c.add(FahrenheitTF);
		c.add(lblcent);
		c.add(CentigradeTF);
		c.add(lblkelv);
		c.add(KelvinTF);
		
		c.setSize(WIDTH, HEIGHT);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);	
}	
	   class FahrHandler implements ActionListener
	  {
	     public void actionPerformed(ActionEvent e)
		  {
		     double fahrenheit, centigrade, kelvin;
			  
			  
			  fahrenheit = FahrenheitTF.getText(fahrEntered); //Get Fahrenheit numbers and do math :)!!!
			  
			  centigrade = (FTOC) * (fahrenheit - OFFSET); //centigrade = (5/9) * (fahrenheit - 32)
			  
			  kelvin = centigrade + KOFFSET; //kelvin = centigrade degrees + 273(<~KOFFset)
			  
			  CentigradeTF = Double.parseDouble.setText(dfCent.format(centigrade));
			  
			  KelvinTF = Double.parseDouble.setText(dfKelv.format(kelvin));
		  }
		}
		
		class CentHandler implements ActionListener
		{
		  public void actionPerformed(ActionEvent e)
		  {
		    double centigrade, fahrenheit, kelvin;
			 
			 centigrade = CentigradeTF.getText();
			 
			 fahrenheit = (CTOF) * (centigrade - OFFSET);
			 
			 kelvin = centigrade + KOFFSET;
			 
			 FahrenheitTF = Double.parseDouble.setText(dfFahr.format(fahrenheit));
			 
			 KelvinTF = Double.parseDouble.setText(dfKelv.format(kelvin));
		 }
	}
	
	class KelvHandler implements ActionListener
	{
	  public void actionPerformed(ActionEvent e)
	  {
	    double centigrade, fahrenheit, kelvin;
  		 
		 kelvin = KelvinTF.getText();
		 
		 fahrenheit = ((Kelvin - 273) * CTOF) + 32;
		 
		 centigrade = kelvin - KOFFSET;
		 
		 FahrenheitTF = Double.parseDouble.setText(dfFahr.format(fahrenheit));
		 
		 CentigradeTF = Double.parseDouble.setText(dfCent.format(centigrade));
		
	  }
	}
   
	public static void main(String args[])
	{
	  TempConversion tempConvert = new TempConversion();
	 }
	}

(On my java compiler I have 10 errors to solve)

package Autofill;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;


public class TempConversion extends JFrame

{

//Math constants start

private static int OFFSET = 32;

private static double FTOC = 5/9;

private static double CTOF = 9/5;

private static int KOFFSET = 273; //Kelvin Offset

private static int WIDTH = 700;

private static int HEIGHT = 150;

 

//TextFields Start

private JTextField CentigradeTF;

private JTextField FahrenheitTF;

private JTextField KelvinTF;

 

//Labels start

private JLabel lblcent;

private JLabel lblkelv;

private JLabel lblfahr;

 

//Decimal Formats

DecimalFormat dfFahr = new DecimalFormat(".");

DecimalFormat dfCent = new DecimalFormat(".");

DecimalFormat dfKelv = new DecimalFormat(".");

 

 

 

//Handlers start

private CentHandler CentigradeHandler;

private FahrHandler FahrenheitHandler;

private KelvHandler KelvinHandler;

 

public TempConversion()

{

super("Temperature Conversion Program v. 1.0");

Container c = getContentPane();

 

c.setLayout(new GridLayout(5,8));

 

lblfahr = new JLabel("Fahrenheit: ", SwingConstants.RIGHT);

lblcent = new JLabel("Centigrade: ", SwingConstants.RIGHT);

lblkelv = new JLabel("Kelvin: ", SwingConstants.RIGHT);

 

FahrenheitTF = new JTextField(15);

CentigradeTF = new JTextField(15);

KelvinTF = new JTextField(15);

 

CentHandler CentigradeHandler = new CentHandler();

FahrHandler FahrenheitHandler = new FahrHandler();

KelvHandler KelvinHandler = new KelvHandler();

 

FahrenheitTF.addActionListener(FahrenheitHandler);

CentigradeTF.addActionListener(CentigradeHandler);

KelvinTF.addActionListener(KelvinHandler);

 

//Add Components to Container

c.add(lblfahr);

c.add(FahrenheitTF);

c.add(lblcent);

c.add(CentigradeTF);

c.add(lblkelv);

c.add(KelvinTF);

 

c.setSize(WIDTH, HEIGHT);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

}

class FahrHandler implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

double fahrenheit, centigrade, kelvin;

 

 

fahrenheit = Double.parseDouble( FahrenheitTF.getText()); //Get Fahrenheit numbers and do math :)!!!

 

centigrade = (FTOC) * (fahrenheit - OFFSET); //centigrade = (5/9) * (fahrenheit - 32)

 

kelvin = centigrade + KOFFSET; //kelvin = centigrade degrees + 273(<~KOFFset)

 

CentigradeTF.setText(dfCent.format(centigrade));

 

KelvinTF.setText(dfKelv.format(kelvin));

}

}

 

class CentHandler implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

double centigrade, fahrenheit, kelvin;

 

centigrade =Double.parseDouble( CentigradeTF.getText());

 

fahrenheit = (CTOF) * (centigrade - OFFSET);

 

kelvin = centigrade + KOFFSET;

 

FahrenheitTF.setText(dfFahr.format(fahrenheit));

 

KelvinTF.setText(dfKelv.format(kelvin));

}

}

 

class KelvHandler implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

double centigrade, fahrenheit, kelvin;

 

kelvin =Double.parseDouble( KelvinTF.getText());

 

fahrenheit = ((kelvin - 273) * CTOF) + 32;

 

centigrade = kelvin - KOFFSET;

 

FahrenheitTF.setText(dfFahr.format(fahrenheit));

 

CentigradeTF.setText(dfCent.format(centigrade));

 

}

}

 

public static void main(String args[])

{

TempConversion tempConvert = new TempConversion();

}

}

What's the problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.