forked from hummel/PR1-Spreadsheet
Standardabweichung implementiert
parent
e73b24e520
commit
1436a72c26
|
@ -174,9 +174,16 @@ public class Spreadsheet {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung
|
else if (formula.startsWith("STABW(")) { // e.g. STABW(C6:D8) -> Standardabweichung
|
||||||
result = "TODO"; // TODO
|
String[] onlyCells = formula.substring(6, formula.length() - 1).split(":");
|
||||||
else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert
|
|
||||||
|
if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) {
|
||||||
|
result = "" + statbw(onlyCells[0], onlyCells[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert
|
||||||
result = "TODO"; // TODO
|
result = "TODO"; // TODO
|
||||||
else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung
|
else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung
|
||||||
result = "TODO"; // TODO
|
result = "TODO"; // TODO
|
||||||
|
@ -193,6 +200,8 @@ public class Spreadsheet {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method for calculating the sum of a rectangular block of cells, such as from A1 to B3.
|
* Method for calculating the sum of a rectangular block of cells, such as from A1 to B3.
|
||||||
* @param startCellName The name of the cell in the upper left corner of the rectangle.
|
* @param startCellName The name of the cell in the upper left corner of the rectangle.
|
||||||
|
@ -209,7 +218,7 @@ public class Spreadsheet {
|
||||||
return summe;
|
return summe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Javadoc comments
|
||||||
private long pro(String startCellName, String endCellName) {
|
private long pro(String startCellName, String endCellName) {
|
||||||
int werte[]=getValues(startCellName,endCellName);
|
int werte[]=getValues(startCellName,endCellName);
|
||||||
|
|
||||||
|
@ -220,6 +229,7 @@ public class Spreadsheet {
|
||||||
return produkt;
|
return produkt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Javadoc comments
|
||||||
private long mit(String startCellName, String endCellName) {
|
private long mit(String startCellName, String endCellName) {
|
||||||
int werte[]=getValues(startCellName,endCellName);
|
int werte[]=getValues(startCellName,endCellName);
|
||||||
|
|
||||||
|
@ -231,6 +241,33 @@ public class Spreadsheet {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Javadoc comments
|
||||||
|
private double statbw(String startCellName, String endCellName) {
|
||||||
|
int werte[]=getValues(startCellName,endCellName);
|
||||||
|
|
||||||
|
if (werte.length < 2) {
|
||||||
|
return 0; // Die Standardabweichung für weniger als zwei Werte ist 0
|
||||||
|
}
|
||||||
|
|
||||||
|
double summe = 0.0;
|
||||||
|
for (double i : werte) {
|
||||||
|
summe += i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Durchschnitt des Arrays berechnen
|
||||||
|
double mittel = summe / werte.length;
|
||||||
|
|
||||||
|
// abweichung zum mittelwert berchnen und quadrieren
|
||||||
|
double standardDeviation = 0.0;
|
||||||
|
for (double wert : werte) {
|
||||||
|
standardDeviation += Math.pow(wert - mittel, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.sqrt(standardDeviation / werte.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Javadoc comments
|
// TODO: Javadoc comments
|
||||||
private int[] getValues(String startCellName, String endCellName) {
|
private int[] getValues(String startCellName, String endCellName) {
|
||||||
int startZeile=getRow(startCellName);
|
int startZeile=getRow(startCellName);
|
||||||
|
|
Loading…
Reference in New Issue