1
0
Fork 0

min value of a cell block

main
ERANZER 2024-01-05 20:18:26 +01:00
parent 3f9b7a7091
commit 9096432995
1 changed files with 19 additions and 2 deletions

View File

@ -155,8 +155,13 @@ public class Spreadsheet {
result = "" + max(formula.substring(4, 6), formula.substring(7, 10)); result = "" + max(formula.substring(4, 6), formula.substring(7, 10));
else else
result = "" + max(formula.substring(4, 6), formula.substring(7, 9)); result = "" + max(formula.substring(4, 6), formula.substring(7, 9));
else if (formula.startsWith("MIN(")) // e.g. MAX(A1:A10) -> Standardabweichung else if (formula.startsWith("MIN("))
result = "TODO"; // TODO if(formula.length()==12)
result = "" + min(formula.substring(4, 7), formula.substring(8, 11));
else if(formula.length()==11)
result = "" + min(formula.substring(4, 6), formula.substring(7, 10));
else
result = "" + min(formula.substring(4, 6), formula.substring(7, 9));
else if (!formula.isEmpty()) { else if (!formula.isEmpty()) {
try { try {
result = "" + calculate(formula); result = "" + calculate(formula);
@ -229,6 +234,18 @@ public class Spreadsheet {
} }
return max; return max;
} }
private int min(String startCellName,String endCellName) {
int min=Integer.MAX_VALUE;
for(int i=startCellName.charAt(0)-'A'; i<=endCellName.charAt(0)-'A'; i++) {
for(int j=Integer.parseInt(startCellName.substring(1))-1; j<=Integer.parseInt(endCellName.substring(1))-1; j++) {
if(cells[j][i].isEmpty())
continue;
else if(min>Integer.parseInt(cells[j][i].getValue()))
min=Integer.parseInt(cells[j][i].getValue());
}
}
return min;
}
/** /**
* This method calculates the result of a "normal" algebraic expression. It only needs to support * This method calculates the result of a "normal" algebraic expression. It only needs to support