forked from hummel/PR1-Spreadsheet
Maximal-Berechnung Implementiert
parent
4c05674bb5
commit
c7af9a2a5e
|
@ -174,7 +174,7 @@ public class Spreadsheet {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else if (formula.startsWith("STABW(")) { // e.g. STABW(C6:D8) -> Standardabweichung
|
else if (formula.startsWith("STABW(")) { // e.g. STABW(C6:D8) -> minimal-wert
|
||||||
String[] onlyCells = formula.substring(6, formula.length() - 1).split(":");
|
String[] onlyCells = formula.substring(6, formula.length() - 1).split(":");
|
||||||
|
|
||||||
if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) {
|
if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) {
|
||||||
|
@ -194,8 +194,13 @@ public class Spreadsheet {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung
|
else if (formula.startsWith("MAX(")) {// e.g. MAX(A1:A10) -> maximal-wert
|
||||||
result = "TODO"; // TODO
|
String[] onlyCells = formula.substring(4, formula.length() - 1).split(":");
|
||||||
|
if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) {
|
||||||
|
result = "" + max(onlyCells[0], onlyCells[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if (!formula.isEmpty()) {
|
else if (!formula.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
result = "" + calculate(formula); //calculates the result of a "normal" algebraic expression.
|
result = "" + calculate(formula); //calculates the result of a "normal" algebraic expression.
|
||||||
|
@ -213,6 +218,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.
|
||||||
|
@ -294,11 +301,29 @@ public class Spreadsheet {
|
||||||
minValue = werte[i];
|
minValue = werte[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return minValue;
|
return minValue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private long max(String startCellName, String endCellName) {
|
||||||
|
int werte[]=getValues(startCellName,endCellName);
|
||||||
|
|
||||||
|
if (werte.length == 0) {
|
||||||
|
return 0; // Handle an empty array as needed
|
||||||
|
}
|
||||||
|
|
||||||
|
int maxValue = werte[0];
|
||||||
|
|
||||||
|
for (int i = 1; i < werte.length; i++) {
|
||||||
|
if (werte[i] > maxValue) {
|
||||||
|
maxValue = werte[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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