1
0
mirror of https://github.com/2martens/uni.git synced 2026-05-06 19:36:26 +02:00

ID-5: Aufgabe 2 bearbeitet

This commit is contained in:
Jim Martens
2014-05-09 14:39:09 +02:00
parent 64a4762a1f
commit 4d8ed895e2
10 changed files with 542 additions and 0 deletions

View File

@ -0,0 +1,41 @@
import java.util.Observable;
public class Temperature extends Observable {
private int _celsius;
private int _fahrenheit;
public Temperature() {
_celsius = 0;
_fahrenheit = 32;
}
public int getCelsiusTemperature() {
return _celsius;
}
public int getFahrenheitTemperature() {
return _fahrenheit;
}
public void setCelsiusTemperature(int celsius) {
_celsius = celsius;
_fahrenheit = convertToFahrenheit(_celsius);
setChanged();
notifyObservers();
}
public void setFahrenheitTemperature(int fahrenheit) {
_fahrenheit = fahrenheit;
_celsius = convertToCelsius(fahrenheit);
setChanged();
notifyObservers();
}
private int convertToFahrenheit(int celsius) {
return Math.round(1.8f * celsius + 32);
}
private int convertToCelsius(int fahrenheit) {
return Math.round(5.0f / 9.0f * (fahrenheit - 32));
}
}