Created
October 26, 2012 14:59
-
-
Save delucas/3959271 to your computer and use it in GitHub Desktop.
Ejercicio de Temperaturas resuelto en clase - UNTreF EdD 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Escala { | |
FAHRENHEIT, CELSIUS, KELVIN | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Temperatura { | |
private Double temperaturaEnCelsius; | |
public void setValorEnFahrenheit(Double temperatura) { | |
this.temperaturaEnCelsius = convertirFahrenheitACelsius(temperatura); | |
} | |
public void setValorEnCelsius(Double temperatura) { | |
this.temperaturaEnCelsius = temperatura; | |
} | |
public void setValorEnKelvin(Double temperatura) { | |
this.temperaturaEnCelsius = convertirKelvinACelsius(temperatura); | |
} | |
public Double getValorEnFahrenheit() { | |
return convertirCelsiusAFahrenheit(this.temperaturaEnCelsius); | |
} | |
public Double getValorEnCelsius() { | |
return this.temperaturaEnCelsius; | |
} | |
public Double getValorEnKelvin() { | |
return convertirCelsiusAKelvin(this.temperaturaEnCelsius); | |
} | |
private Double convertirFahrenheitACelsius(Double temperatura) { | |
return (temperatura - 32.0) * (5.0 / 9.0); | |
} | |
private Double convertirKelvinACelsius(Double temperatura) { | |
return temperatura - 273.0; | |
} | |
private Double convertirCelsiusAFahrenheit(Double temperatura){ | |
return temperatura * (9.0 / 5.0) + 32.0; | |
} | |
private Double convertirCelsiusAKelvin(Double temperatura){ | |
return temperatura + 273.0; | |
} | |
// public void setValor(Double temperatura, String unidad) { | |
// if ("Celsius".equals(unidad)) { | |
// this.temperaturaEnCelsius = temperatura; | |
// } else if ("Fahrenheit".equals(unidad)) { | |
// this.temperaturaEnCelsius = convertirFahrenheitACelsius(temperatura); | |
// } else { | |
// this.temperaturaEnCelsius = convertirKelvinACelsius(temperatura); | |
// } | |
// } | |
public void setValor(Double temperatura, Escala escala) { | |
if (Escala.CELSIUS == escala) { | |
this.temperaturaEnCelsius = temperatura; | |
} else if (Escala.FAHRENHEIT == escala) { | |
this.temperaturaEnCelsius = convertirFahrenheitACelsius(temperatura); | |
} else if (Escala.KELVIN == escala){ | |
this.temperaturaEnCelsius = convertirKelvinACelsius(temperatura); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment