Converted everything to work with polymorphism

Added "Grootheid" to act as a parent to all children classes, it allows
the main "Weerstation" to update them all better and with cleaner code.
This commit is contained in:
Kenneth van Ewijk
2014-10-11 17:46:31 +02:00
parent 94cab3188e
commit a0c37c1a23
13 changed files with 340 additions and 776 deletions
+86
View File
@@ -0,0 +1,86 @@
import java.util.ArrayList;
public class Grootheid
{
// instance variables - replace the example below with your own
public double avg;
public double max;
public double min;
public double current;
//constructor
public Grootheid(){
avg = 0;
max = 0;
min = 0;
current = 0;
}
//getters & setters
public double getCurrent() {
return current;
}
public void setCurrent(double current) {
this.current = current;
}
public double getMax() {
return max;
}
public void setMax(double max) {
this.max= max;
}
public double getMin() {
return min;
}
public void setMin(double min) {
this.min = min;
}
public double getAvg() {
return avg;
}
public void setAvg(double avg) {
this.avg = avg;
}
//Methods
public void calculateMaxMinAvg(ArrayList<Double> laatste24uur){
double tempMax = 0;
double tempAvg = 0;
double tempMin = laatste24uur.get(0);
for(double ms : laatste24uur){
if(ms > tempMax){
tempMax = ms;
}
if(ms < tempMin){
tempMin = ms;
}
tempAvg += ms;
}
tempAvg /= laatste24uur.size();
setMax(tempMax);
setMin(tempMin);
setAvg(tempAvg);
}
public void updateRecent(Measurement measurement1){
}
public void update24Hour(ArrayList<Measurement> measurement2){
}
public void display(){
GUIboard.writeUpperDigits(getCurrent());
GUIboard.writeLeftDigits(getMax());
GUIboard.writeRightDigits(getMin());
}
}