From bbe478ff81c45bc5216a2e19c2439520eb526bac Mon Sep 17 00:00:00 2001 From: 3011357 <3011357@stud.hs-mannheim.de> Date: Sat, 6 Jan 2024 20:13:02 +0100 Subject: [PATCH] =?UTF-8?q?prod()=20Methode=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../informatik/spreadsheet/Spreadsheet.java | 24 +++++++++++++++---- 1 file changed, 20 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 a123873..cba2965 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -120,7 +120,7 @@ public class Spreadsheet { if (formula.startsWith("SUMME(")) // e.g. SUMME(A3:A8) result = "" + sum(formula.substring(6, colon), endSubstring); else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) - result = "" + prod(formula.substring(9, colon), endSubstring); + result = "" + prod(formula.substring(8, colon), endSubstring); else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) result = "" + mit(formula.substring(12, colon), endSubstring); else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung @@ -153,8 +153,7 @@ public class Spreadsheet { 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); + String value = get((row - 1), (col - 'A')); //"-1" because we start with 1 instead of 0. "-A" because A in ascii is 65, but we start with 0 if(!value.isEmpty()){ result += Long.parseLong(value); @@ -171,9 +170,26 @@ public class Spreadsheet { * @return The product calculated. */ private long prod(String startCellName, String endCellName) { + long result = 0; + for(char col = startCellName.charAt(0); col <= endCellName.charAt(0); col++){ - return 0; + 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(result == 0){ + result = Long.parseLong(value); + + } + else if(!value.isEmpty() && !(value.equals("0"))){ + result *= Long.parseLong(value); + } + + } + } + return result; } /**