1
0
Fork 0

Minimum-berechnung implementiert

master
devra 2024-01-08 22:29:05 +01:00
parent 1436a72c26
commit 4c05674bb5
1 changed files with 36 additions and 5 deletions

View File

@ -183,8 +183,17 @@ public class Spreadsheet {
}
else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert
result = "TODO"; // TODO
else if (formula.startsWith("MIN(")) {
String[] onlyCells = formula.substring(4, formula.length() - 1).split(":");
if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) {
result = "" + min(onlyCells[0], onlyCells[1]);
}
}
else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung
result = "TODO"; // TODO
else if (!formula.isEmpty()) {
@ -202,6 +211,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.
@ -258,16 +269,36 @@ public class Spreadsheet {
double mittel = summe / werte.length;
// abweichung zum mittelwert berchnen und quadrieren
double standardDeviation = 0.0;
double abweichung = 0.0;
for (double wert : werte) {
standardDeviation += Math.pow(wert - mittel, 2);
abweichung += Math.pow(wert - mittel, 2);
}
return Math.sqrt(standardDeviation / werte.length);
return Math.sqrt(abweichung / werte.length);
}
private long min(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName);
if (werte.length == 0) {
return 0; // Handle an empty array as needed
}
int minValue = werte[0];
for (int i = 1; i < werte.length; i++) {
if (werte[i] < minValue) {
minValue = werte[i];
}
}
return minValue;
}
// TODO: Javadoc comments
private int[] getValues(String startCellName, String endCellName) {
int startZeile=getRow(startCellName);