1
0
Fork 0

Standardabweichung implementiert

master
devra 2024-01-08 22:04:31 +01:00
parent e73b24e520
commit 1436a72c26
1 changed files with 41 additions and 4 deletions

View File

@ -174,8 +174,15 @@ public class Spreadsheet {
else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung
result = "TODO"; // TODO
else if (formula.startsWith("STABW(")) { // e.g. STABW(C6:D8) -> Standardabweichung
String[] onlyCells = formula.substring(6, formula.length() - 1).split(":");
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
else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung
@ -193,6 +200,8 @@ public class Spreadsheet {
/**
* 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.
@ -209,7 +218,7 @@ public class Spreadsheet {
return summe;
}
// TODO: Javadoc comments
private long pro(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName);
@ -220,6 +229,7 @@ public class Spreadsheet {
return produkt;
}
// TODO: Javadoc comments
private long mit(String startCellName, String 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
private int[] getValues(String startCellName, String endCellName) {
int startZeile=getRow(startCellName);