From 44e9e9bc9c8c200f551d6825546f2f6de50f67b2 Mon Sep 17 00:00:00 2001 From: 3011357 <3011357@stud.hs-mannheim.de> Date: Sat, 6 Jan 2024 15:30:59 +0100 Subject: [PATCH] =?UTF-8?q?Methoden=20zu=20den=20Formeln=20deklariert.=20I?= =?UTF-8?q?n=20evaluateCell()=20Cell=20references=20f=C3=BCr=20two-digits?= =?UTF-8?q?=20erm=C3=B6glicht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../informatik/spreadsheet/Spreadsheet.java | 80 ++++++++++++++++--- PR1-Spreadsheet.iml | 17 ++++ 2 files changed, 88 insertions(+), 9 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 88350d7..63e20ee 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -117,19 +117,21 @@ public class Spreadsheet { private void evaluateCell(int row, int col) { String formula = cells[row][col].getFormula(); String result = ""; + int colon = formula.indexOf(':'); + String endSubstring = formula.substring((colon + 1), (formula.length()-1)); 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 + result = "" + sum(formula.substring(6, colon), endSubstring); else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) - result = "TODO"; // TODO + result = "" + prod(formula.substring(9, colon), endSubstring); else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) - result = "TODO"; // TODO + result = "" + mit(formula.substring(12, colon), endSubstring); 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 - else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung - result = "TODO"; // TODO + result = "" + stabw(formula.substring(7, colon), endSubstring); + else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> kleinster Wert + result = "" + min(formula.substring(5, colon), endSubstring); + else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> größter Wert + result = "" + max(formula.substring(5, colon), endSubstring); else if (!formula.isEmpty()) { try { result = "" + calculate(formula); @@ -148,11 +150,71 @@ public class Spreadsheet { * @return The sum calculated. */ private long sum(String startCellName, String endCellName) { - // TODO implement return 0; } + /** + * Method for calculating the product 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. + * @param endCellName The name of the cell in the lower right corner of the rectangle. + * @return The product calculated. + */ + private long prod(String startCellName, String endCellName) { + + + return 0; + } + + /** + * Method for calculating the arithmetic average 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. + * @param endCellName The name of the cell in the lower right corner of the rectangle. + * @return The arithmetic average calculated. + */ + private long mit(String startCellName, String endCellName) { + + + return 0; + } + + /** + * Method for calculating the standard deviation 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. + * @param endCellName The name of the cell in the lower right corner of the rectangle. + * @return The standard deviation calculated. + */ + private long stabw(String startCellName, String endCellName) { + + + return 0; + } + + /** + * Method for finding the maximum value 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. + * @param endCellName The name of the cell in the lower right corner of the rectangle. + * @return The minimum value of the block. + */ + private long min(String startCellName, String endCellName) { + + + return 0; + } + + /** + * Method for finding the maximum value 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. + * @param endCellName The name of the cell in the lower right corner of the rectangle. + * @return The maximum value of the block. + */ + private long max(String startCellName, String endCellName) { + + + return 0; + } + + /** * This method calculates the result of a "normal" algebraic expression. It only needs to support * expressions like =B4 or =2+A3-B2, i.e. only with int numbers and other cells and with plus, diff --git a/PR1-Spreadsheet.iml b/PR1-Spreadsheet.iml index ea954f0..c319eea 100644 --- a/PR1-Spreadsheet.iml +++ b/PR1-Spreadsheet.iml @@ -4,8 +4,25 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file