Snippets

Ettar Java Temperatur

Created by Ettar

public class Temperatur {
	
	private double celsius;
	private double kelvin;
	private double fahrenheit;
	
	private double calcTempCelFahr(double temp){
		return (temp-32)*0.55556;
	}
	
	private double calcTempCelKel(double temp){
		return temp-273;
	}
	
	private double calcTempKelCel(double temp){
		double tmp = temp+273;
		if(tmp<0){
			return 0;
		}
		else{
			return tmp;
		}
	}
	
	private double calcTempFahr(double temp){
		return temp*1.8+32;
	}
	
	public void setCel(double temp){
		this.celsius=temp;
		this.kelvin=calcTempKelCel(temp);
		this.fahrenheit=calcTempFahr(temp);
	}
	
	public void setKel(double temp){
		if(temp<0)
			temp=0;
		this.celsius=calcTempCelKel(temp);
		this.kelvin=temp;
		this.fahrenheit=calcTempFahr(this.celsius);
	}
	
	public void setFahr(double temp){
		this.celsius=calcTempCelFahr(temp);
		this.kelvin=calcTempKelCel(this.celsius);
		this.fahrenheit=temp;
	}
	
	public double getCel(){
		return celsius;
	}
	public double getKel(){
		return kelvin;
	}
	public double getFahr(){
		return fahrenheit;
	}
	
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.