From bbbaf7473a393164ef296dd9d2d61f3b79685365 Mon Sep 17 00:00:00 2001 From: 3011357 <3011357@stud.hs-mannheim.de> Date: Sat, 6 Jan 2024 19:02:13 +0100 Subject: [PATCH] =?UTF-8?q?sum()=20Methode=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../informatik/spreadsheet/Spreadsheet.java | 18 ++++++++++++++---- 1 file changed, 14 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 63e20ee..a123873 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -76,7 +76,6 @@ public class Spreadsheet { * @param path The file to read. * @param separator The char used to split up the input, e.g. a comma or a semicolon. * @param startCellName The upper left cell where data from the CSV file should be inserted. - * @return Nothing. * @exception IOException If path does not exist. */ public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException { @@ -86,7 +85,6 @@ public class Spreadsheet { /** * A method for saving data to a CSV file. * @param path The file to write. - * @return Nothing. * @exception IOException If path does not exist. */ public void saveCsv(String path) throws FileNotFoundException { @@ -112,7 +110,6 @@ public class Spreadsheet { * This method does the actual evaluation/calcluation of a specific cell * @param row the row of the cell to be evaluated * @param col the col of the cell to be evaluated - * @return Nothing. */ private void evaluateCell(int row, int col) { String formula = cells[row][col].getFormula(); @@ -150,8 +147,21 @@ public class Spreadsheet { * @return The sum calculated. */ private long sum(String startCellName, String endCellName) { + long result = 0; - return 0; + for(char col = startCellName.charAt(0); col <= endCellName.charAt(0); col++){ + + for(int row = Integer.parseInt(startCellName.substring(1)); row <= Integer.parseInt(endCellName.substring(1)); row++) { + + String value = get((row - 1), (col - 'A')); + System.out.println(value); + + if(!value.isEmpty()){ + result += Long.parseLong(value); + } + } + } + return result; } /**