min value of a cell block
parent
3f9b7a7091
commit
9096432995
|
@ -155,8 +155,13 @@ public class Spreadsheet {
|
|||
result = "" + max(formula.substring(4, 6), formula.substring(7, 10));
|
||||
else
|
||||
result = "" + max(formula.substring(4, 6), formula.substring(7, 9));
|
||||
else if (formula.startsWith("MIN(")) // e.g. MAX(A1:A10) -> Standardabweichung
|
||||
result = "TODO"; // TODO
|
||||
else if (formula.startsWith("MIN("))
|
||||
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()) {
|
||||
try {
|
||||
result = "" + calculate(formula);
|
||||
|
@ -229,6 +234,18 @@ public class Spreadsheet {
|
|||
}
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue