From 091418cbdee43d754b604420aa70090ab8b0ab0c Mon Sep 17 00:00:00 2001 From: 3010564 <3010564@stud.hs-mannheim.de> Date: Thu, 11 Jan 2024 17:34:36 +0100 Subject: [PATCH] =?UTF-8?q?Kleines=20Men=C3=BC=20erstellt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Zeilen und Spaltenbegrenzung csvReader erstellt Summenformel und Produktformel erstellt. + Die Möglichkeit erstellt vorhandene Textdatei zu verändern und diese zu Speichern. Wird beim auslesen auch verändert ausgegeben. Mittelwert Min und Max Methoden hinzugefügt --- .../informatik/spreadsheet/Spreadsheet.java | 71 +++++++++++++++++-- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 0a30454..4761765 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -153,18 +153,18 @@ public class Spreadsheet { String formula = cells[row][col].getFormula(); String result = ""; - if (formula.startsWith("SUMME(")) // e.g. SUMME(A3:A8) + 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 else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) - result = "" + multiplier(formula.substring(6, 8), formula.substring(9, 11)); // TODO + result = "" + multiplier(formula.substring(8, 10), formula.substring(11, 13)); // TODO else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) - result = "TODO"; // TODO + result = "" + mittelwert(formula.substring(11, 13), formula.substring(14, 16)); // TODO else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung result = "TODO"; // TODO else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert - result = "TODO"; // TODO + result = "" + min(formula.substring(4, 6), formula.substring(7, 9)); // TODO else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung - result = "TODO"; // TODO + result = "" + max(formula.substring(4, 6), formula.substring(7, 9)); // TODO else if (!formula.isEmpty()) { try { result = "" + calculate(formula); @@ -175,7 +175,7 @@ public class Spreadsheet { cells[row][col].setValue("" + result); } - + //substring start und ende auf die entsprechende Wortlänge bei der Bedingung anpassen /** * Method for calculating the sum of a rectangular block of cells, such as from A1 to B3. * @param startCellName The name of the cell in the upper left corner of the rectangle. @@ -216,6 +216,65 @@ public class Spreadsheet { return result; } + private long mittelwert(String startCellName, String endCellName) { + + int startRow = getRow(startCellName); + int startCol = getCol(startCellName); + int endRow = getRow(endCellName); + int endCol = getCol(endCellName); + int counter = 0; + long summe = 0; + + long result = 0; + + for (int i = startRow; i <= endRow; i++) { + for (int j = startCol; j <= endCol; j++) { + counter++; + summe += (Integer.parseInt(cells[i][j].getValue())); + } + } + result = summe / counter; + + return result; + } + private long min(String startCellName, String endCellName) { + int startRow = getRow(startCellName); + int startCol = getCol(startCellName); + int endRow = getRow(endCellName); + int endCol = getCol(endCellName); + long result = 0; + + for (int i = startRow; i <= endRow; i++) { + for (int j = startCol; j <= endCol; j++) { + + result = (Integer.parseInt(cells[i][j].getValue())); + if(result > (Integer.parseInt(cells[i][j].getValue()))) { + result = (Integer.parseInt(cells[i][j].getValue())); + } + + } + } + return result; + } + + private long max(String startCellName, String endCellName) { + int startRow = getRow(startCellName); + int startCol = getCol(startCellName); + int endRow = getRow(endCellName); + int endCol = getCol(endCellName); + long result = 0; + + for (int i = startRow; i <= endRow; i++) { + for (int j = startCol; j <= endCol; j++) { + + if(result < (Integer.parseInt(cells[i][j].getValue()))) { + result = (Integer.parseInt(cells[i][j].getValue())); + } + + } + } + return result; + } // TODO implement