1
0
Fork 0

Spreadsheet evaluateCell SUMME adapt to cells with two digits.

pull/1/head
selim 2023-12-26 03:45:32 +01:00
parent f756a7cd67
commit 10682d1d92
1 changed files with 21 additions and 4 deletions

View File

@ -147,7 +147,18 @@ public class Spreadsheet {
String result = "";
if (formula.startsWith("SUMME(")) // e.g. SUMME(A3:A8)
result = "" + sum(formula.substring(6, 8), formula.substring(9, 11)); // TODO adapt to cells with two digits
if(formula.length()<13)
result = "" + sum(formula.substring(6, 8), formula.substring(9, 11));
else if(formula.length()<14&&formula.substring(6, 9).contains(":"))
result = "" + sum(formula.substring(6, 8), formula.substring(9, 12));
else if(formula.length()<14&&!formula.substring(6, 9).contains(":"))
result = "" + sum(formula.substring(6, 9), formula.substring(10, 12));
else if(formula.length()<15)
result = "" + sum(formula.substring(6, 9), formula.substring(10, 13));
else
result = "0";
else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9)
result = "TODO"; // TODO
else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5)
@ -166,7 +177,7 @@ public class Spreadsheet {
}
}
cells[row][col].setValue("" + result);
cells[row][col].setValue(result);
}
/**
@ -177,9 +188,15 @@ public class Spreadsheet {
* @return The sum calculated.
*/
private long sum(String startCellName, String endCellName) {
// TODO implement
long result = 0;
return 0;
for(int r = getRow(startCellName); r<getRow(endCellName)+1; r++)
for(int c = getCol(startCellName); c<getCol(endCellName)+1; c++)
try {
result += Long.parseLong(cells[r][c].getValue());
} catch (NumberFormatException n){}
return result;
}
/**