From 10f0aef19abec8c4d635d7df95b921ebde4f0701 Mon Sep 17 00:00:00 2001 From: 3011357 <3011357@stud.hs-mannheim.de> Date: Sat, 6 Jan 2024 20:25:15 +0100 Subject: [PATCH] =?UTF-8?q?mit()=20Methode=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../informatik/spreadsheet/Spreadsheet.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index cba2965..18dcd7a 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -122,13 +122,13 @@ public class Spreadsheet { else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) result = "" + prod(formula.substring(8, colon), endSubstring); else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) - result = "" + mit(formula.substring(12, colon), endSubstring); + result = "" + mit(formula.substring(11, colon), endSubstring); else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung - result = "" + stabw(formula.substring(7, colon), endSubstring); + result = "" + stabw(formula.substring(6, colon), endSubstring); else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> kleinster Wert - result = "" + min(formula.substring(5, colon), endSubstring); + result = "" + min(formula.substring(4, colon), endSubstring); else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> größter Wert - result = "" + max(formula.substring(5, colon), endSubstring); + result = "" + max(formula.substring(4, colon), endSubstring); else if (!formula.isEmpty()) { try { result = "" + calculate(formula); @@ -199,9 +199,25 @@ public class Spreadsheet { * @return The arithmetic average calculated. */ private long mit(String startCellName, String endCellName) { + long result = 0; + int counter = 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')); + + if(!value.isEmpty()){ + result += Long.parseLong(value); + }else{ + continue; + } + + counter++; + } + } + result /= counter; + return result; } /**