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:
+28
-84
@@ -1,88 +1,32 @@
|
||||
package weerstation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class WindChill {
|
||||
|
||||
//fields
|
||||
private double currentWindChill;
|
||||
private double maxWindChill;
|
||||
private double minWindChill;
|
||||
private double avgWindChill;
|
||||
|
||||
//constructor
|
||||
public WindChill(Measurement measurement1, ArrayList<Measurement> measurement2){
|
||||
updateRecent(measurement1);
|
||||
update24Hour(measurement2);
|
||||
}
|
||||
|
||||
//getters & setters
|
||||
public double getCurrentWindChill() {
|
||||
return currentWindChill;
|
||||
}
|
||||
public class WindChill extends Grootheid{
|
||||
|
||||
//constructor
|
||||
public WindChill(Measurement measurement1, ArrayList<Measurement> measurement2){
|
||||
updateRecent(measurement1);
|
||||
update24Hour(measurement2);
|
||||
}
|
||||
|
||||
public void setCurrentWindChill(double currentWindChill) {
|
||||
this.currentWindChill = currentWindChill;
|
||||
}
|
||||
|
||||
public double getMaxWindChill() {
|
||||
return maxWindChill;
|
||||
}
|
||||
|
||||
public void setMaxWindChill(double maxWindChill) {
|
||||
this.maxWindChill = maxWindChill;
|
||||
}
|
||||
|
||||
public double getMinWindChill() {
|
||||
return minWindChill;
|
||||
}
|
||||
|
||||
public void setMinWindChill(double minWindChill) {
|
||||
this.minWindChill = minWindChill;
|
||||
}
|
||||
|
||||
public double getAvgWindChill() {
|
||||
return avgWindChill;
|
||||
}
|
||||
|
||||
public void setAvgWindChill(double avgWindChill) {
|
||||
this.avgWindChill = Math.round(avgWindChill*100)/100;
|
||||
}
|
||||
|
||||
//Methods
|
||||
private void calculateMaxMinAvgWindChill(ArrayList<Measurement> laatste24uur){
|
||||
double max = 0;
|
||||
double min = 1000;
|
||||
float avg = 0;
|
||||
for(Measurement minut :laatste24uur){
|
||||
if(minut.getWindChill() > max){
|
||||
max = minut.getWindChill();
|
||||
}
|
||||
if(minut.getWindChill() < min){
|
||||
min = minut.getWindChill();
|
||||
}
|
||||
avg += minut.getWindChill();
|
||||
}
|
||||
avg /= laatste24uur.size();
|
||||
|
||||
setAvgWindChill(avg);
|
||||
setMaxWindChill(max);
|
||||
setMinWindChill(min);
|
||||
}
|
||||
|
||||
|
||||
public void updateRecent(Measurement measurement1){
|
||||
setCurrentWindChill(measurement1.getWindChill());
|
||||
}
|
||||
public void update24Hour(ArrayList<Measurement> measurement2){
|
||||
calculateMaxMinAvgWindChill(measurement2);
|
||||
}
|
||||
|
||||
public void display(){
|
||||
GUIboard.writeUpperDigits(getCurrentWindChill());
|
||||
GUIboard.writeLeftDigits(getMaxWindChill());
|
||||
GUIboard.writeRightDigits(getMinWindChill());
|
||||
GUIboard.writePageToMatrix("Gevoelstemp in C", "Gemiddelde: " + avgWindChill, "");
|
||||
}
|
||||
|
||||
|
||||
public void updateRecent(Measurement measurement1){
|
||||
setCurrent(measurement1.getWindChill());
|
||||
}
|
||||
public void update24Hour(ArrayList<Measurement> measurement2){
|
||||
|
||||
ArrayList<Double> list = new ArrayList<Double>();
|
||||
|
||||
for(Measurement ms : measurement2)
|
||||
{
|
||||
list.add(ms.getWindChill());
|
||||
}
|
||||
|
||||
calculateMaxMinAvg(list);
|
||||
}
|
||||
|
||||
public void display(){
|
||||
super.display();
|
||||
GUIboard.writePageToMatrix("Gevoelstemperatuur", "Gemiddelde: " + getAvg(), "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user