From 10682d1d929bec7357a1aa99b365fb21abf49d71 Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 03:45:32 +0100 Subject: [PATCH] Spreadsheet evaluateCell SUMME adapt to cells with two digits. --- .../informatik/spreadsheet/Spreadsheet.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 8300eba..7edd11a 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -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