From 6f6cb59f08c15d30278796993fc361c5f4e1b178 Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 03:09:42 +0100 Subject: [PATCH 01/31] Spreadsheet toString updated. --- .../informatik/spreadsheet/Spreadsheet.java | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index ceacf6f..a85722f 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -17,6 +17,7 @@ public class Spreadsheet { /** * Constructor that creates a Spreadsheet of size rows * cols. + * * @param rows number of rows * @param cols number of columns */ @@ -70,11 +71,12 @@ public class Spreadsheet { /** * A method for reading in data from a CSV file. - * @param path The file to read. - * @param separator The char used to split up the input, e.g. a comma or a semicolon. + * + * @param path The file to read. + * @param separator The char used to split up the input, e.g. a comma or a semicolon. * @param starCellName The upper left cell where data from the CSV file should be inserted. * @return Nothing. - * @exception IOException If path does not exist. + * @throws IOException If path does not exist. */ public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException { // TODO: implement this @@ -82,9 +84,10 @@ 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. + * @throws IOException If path does not exist. */ public void saveCsv(String path) throws FileNotFoundException { PrintWriter out = new PrintWriter(path); @@ -96,7 +99,7 @@ public class Spreadsheet { else out.print(cell.getValue()); - if (cell != row[cells[0].length-1]) + if (cell != row[cells[0].length - 1]) out.print(","); } out.println(); @@ -107,6 +110,7 @@ public class Spreadsheet { /** * This method does the actual evaluation/calcluation of a specific cell + * * @param cellName the name of the cell to be evaluated * @return Nothing. */ @@ -129,7 +133,7 @@ public class Spreadsheet { else if (!formula.isEmpty()) { try { result = "" + calculate(formula); - } catch(ArithmeticException ae) { + } catch (ArithmeticException ae) { result = "exc."; } } @@ -139,8 +143,9 @@ public class Spreadsheet { /** * 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. - * @param endCellName The name of the cell in the lower right corner of the rectangle. + * @param endCellName The name of the cell in the lower right corner of the rectangle. * @return The sum calculated. */ private long sum(String startCellName, String endCellName) { @@ -152,9 +157,10 @@ public class Spreadsheet { /** * 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, - * minus, times, split only. An expression always starts with either a number or a cell name. If it - * continues, it is guaranteed that this is followed by an operator and either a number or a + * minus, times, split only. An expression always starts with either a number or a cell name. If it + * continues, it is guaranteed that this is followed by an operator and either a number or a * cell name again. It is NOT required to implement dot before dash or parentheses in formulas. + * * @param formula The expression to be evaluated. * @return The result calculated. */ @@ -181,22 +187,34 @@ public class Spreadsheet { public String toString() { StringBuilder sb = new StringBuilder(); - sb.append(" "); + sb.append(System.lineSeparator()); + sb.append(" |"); for (int i = 0; i < cells[0].length; i++) { - sb.append(" " + (char)('A'+ i) + " | "); + sb.append(" " + (char) ('A' + i) + " |"); } - int rc = 1; for (Cell[] r : cells) { sb.append(System.lineSeparator()); - sb.append(String.format("%2s", rc++) + ": "); + for (int i = 0; i < cells[0].length; i++) { + sb.append("----------------"); + } + sb.append("------"); + sb.append(System.lineSeparator()); + sb.append(String.format(" " + "%2s", rc++) + " |"); for (Cell c : r) { - sb.append(c + " | "); + sb.append(" " + String.format("%13s", c) + " |"); } } + sb.append(System.lineSeparator()); + for (int i = 0; i < cells[0].length; i++) { + sb.append("----------------"); + } + sb.append("------"); + sb.append(System.lineSeparator()); return sb.toString(); - } + + } } \ No newline at end of file -- 2.43.0 From be62fac6885d155a279daf3d4dd24d94dba081dc Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 03:10:36 +0100 Subject: [PATCH 02/31] Spreadsheet toString updated. --- .idea/.gitignore | 8 ++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ PR1-Spreadsheet.iml | 11 +++++++++++ 5 files changed, 39 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 PR1-Spreadsheet.iml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a818314 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b113384 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/PR1-Spreadsheet.iml b/PR1-Spreadsheet.iml new file mode 100644 index 0000000..ea954f0 --- /dev/null +++ b/PR1-Spreadsheet.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file -- 2.43.0 From d9b6ff91400299c4f9a74b97be801a84688977a7 Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 03:12:33 +0100 Subject: [PATCH 03/31] Spreadsheet readCsv implemented. --- .../informatik/spreadsheet/Spreadsheet.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index a85722f..b1b25d9 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -1,8 +1,11 @@ package de.hs_mannheim.informatik.spreadsheet; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -79,7 +82,23 @@ public class Spreadsheet { * @throws IOException If path does not exist. */ public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException { - // TODO: implement this + Scanner sc = new Scanner(new File(path)); + ArrayList memList = new ArrayList<>(); + + while (sc.hasNextLine()) { + memList.add(sc.nextLine()); + } + + String[][] memArr = new String[memList.size()][]; + for(int i = 0; i < memList.size(); i++) + memArr[i] = (memList.get(i)).split(String.valueOf(separator)); + + for (int r = getRow(startCellName); r < memList.size(); r++) + for (int c = getCol(startCellName); c < memList.get(0).length(); c++) + if(c Date: Tue, 26 Dec 2023 03:16:38 +0100 Subject: [PATCH 04/31] Spreadsheet maximum/minimum size rows: 1-99 columns: 1-26 limit implemented. --- .../hs_mannheim/informatik/spreadsheet/Spreadsheet.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index b1b25d9..8c8905b 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -26,7 +26,14 @@ public class Spreadsheet { */ public Spreadsheet(int rows, int cols) { - // TODO limit the maximum size on 99 (1..99) rows and 26 (A..Z) columns + if(rows>99) + rows = 99; + else if(rows<1) + rows = 1; + if(cols < 1) + cols = 1; + else if(cols > 26) + cols = 26; cells = new Cell[rows][cols]; -- 2.43.0 From f756a7cd67cfe6c73454a8619331340e087d03b5 Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 03:25:09 +0100 Subject: [PATCH 05/31] Spreadsheet getRow 3 character fix. --- Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 8c8905b..8300eba 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -73,6 +73,8 @@ public class Spreadsheet { } private int getRow(String cellName) { + if(cellName.length()>2) + return Integer.parseInt(""+cellName.charAt(1)+cellName.charAt(2)) - 1; return cellName.charAt(1) - '1'; } -- 2.43.0 From 10682d1d929bec7357a1aa99b365fb21abf49d71 Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 03:45:32 +0100 Subject: [PATCH 06/31] Spreadsheet evaluateCell SUMME adapt to cells with two digits. --- .../informatik/spreadsheet/Spreadsheet.java | 25 ++++++++++++++++--- 1 file changed, 21 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 8300eba..7edd11a 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -147,7 +147,18 @@ public class Spreadsheet { String result = ""; 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 + if(formula.length()<13) + result = "" + sum(formula.substring(6, 8), formula.substring(9, 11)); + else if(formula.length()<14&&formula.substring(6, 9).contains(":")) + result = "" + sum(formula.substring(6, 8), formula.substring(9, 12)); + else if(formula.length()<14&&!formula.substring(6, 9).contains(":")) + result = "" + sum(formula.substring(6, 9), formula.substring(10, 12)); + else if(formula.length()<15) + result = "" + sum(formula.substring(6, 9), formula.substring(10, 13)); + else + result = "0"; + + else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) result = "TODO"; // TODO else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) @@ -166,7 +177,7 @@ public class Spreadsheet { } } - cells[row][col].setValue("" + result); + cells[row][col].setValue(result); } /** @@ -177,9 +188,15 @@ public class Spreadsheet { * @return The sum calculated. */ private long sum(String startCellName, String endCellName) { - // TODO implement + long result = 0; - return 0; + for(int r = getRow(startCellName); r Date: Tue, 26 Dec 2023 04:13:44 +0100 Subject: [PATCH 07/31] Spreadsheet calculate/evaluateOperator methods implemented. --- .../informatik/spreadsheet/Spreadsheet.java | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 7edd11a..f7877d0 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -210,25 +210,62 @@ public class Spreadsheet { * @return The result calculated. */ private long calculate(String formula) throws ArithmeticException { - Matcher m = Pattern.compile("([A-Z][0-9]*)|[-\\+\\*/]|[0-9]*").matcher(formula); + Matcher m = Pattern.compile("([A-Z][0-9]*)|[-+*/]|[0-9]*").matcher(formula); long res = 0; + long currentOperand = 0; + String currentOperator = "+"; + boolean firstOperator = true; - // TODO implement - - // uncomment the following to see an example how the elements of a formula can be accessed - while (m.find()) { // m.find() must always be used before m.group() + while (m.find()) { String s = m.group(); - if (!s.isEmpty()) { - System.out.println(s); + + if (s.matches(("[0-9]+"))) + currentOperand = Long.parseLong(s); + else if ((s.matches("[A-Z][1-9]*") || s.matches("[A-Z][1-9]*+")) && get(s).isEmpty()) + currentOperand = 0; + else if ((s.matches("[A-Z][1-9]*") || s.matches("[A-Z][1-9]*+"))) { + currentOperand = Long.parseLong(get(s)); + } else { + if (!firstOperator) { + res = evaluateOperator(res, currentOperand, currentOperator); + } else { + res = currentOperand; + firstOperator = false; + } + currentOperator = s; } } + if (!firstOperator) { + res = evaluateOperator(res, currentOperand, currentOperator); + } else + res = currentOperand; + return res; } - // ----- + private long evaluateOperator(long res, long currentOperand, String currentOperator) { + switch (currentOperator) { + case "+": + res += currentOperand; + break; + case "-": + res -= currentOperand; + break; + case "*": + res *= currentOperand; + break; + case "/": + res /= currentOperand; + break; + default: + throw new IllegalArgumentException("Invalid operator: " + currentOperator); + } + return res; + } + ///--- public String toString() { StringBuilder sb = new StringBuilder(); -- 2.43.0 From 096215a33aa4de22b30347679840608e5d1d341a Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 04:49:00 +0100 Subject: [PATCH 08/31] Spreadsheet calculate minor fix and new ui method: updateSpreadsheet. --- .../informatik/spreadsheet/Axel.java | 14 ++++------- .../informatik/spreadsheet/Spreadsheet.java | 23 +++++++++---------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index df720b3..41c5da2 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -11,17 +11,13 @@ public class Axel { public static void main(String[] args) throws FileNotFoundException { Spreadsheet spr = new Spreadsheet(10,10); - - spr.put("A3", "123"); - spr.put("A2", "1"); - - spr.put("B9", "=41+A2"); - spr.put("J5", "=7*6"); - spr.put("J6", "=3/2"); + + spr.cells[2][7].setFormula("=5+3"); + spr.updateSpreadsheet(); + System.out.println(spr); - - spr.saveCsv("/tmp/test.csv"); + // TODO: You might want to put "UI loop" for entering value and formulas here resp. in some UI methods. } diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index f7877d0..94ddeb5 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -210,7 +210,7 @@ public class Spreadsheet { * @return The result calculated. */ private long calculate(String formula) throws ArithmeticException { - Matcher m = Pattern.compile("([A-Z][0-9]*)|[-+*/]|[0-9]*").matcher(formula); + Matcher m = Pattern.compile("([A-Z][0-9]*)|[-+*/]|[0-9]+").matcher(formula); long res = 0; long currentOperand = 0; @@ -244,28 +244,27 @@ public class Spreadsheet { return res; } - private long evaluateOperator(long res, long currentOperand, String currentOperator) { switch (currentOperator) { case "+": - res += currentOperand; - break; + return res + currentOperand; case "-": - res -= currentOperand; - break; + return res - currentOperand; case "*": - res *= currentOperand; - break; + return res * currentOperand; case "/": - res /= currentOperand; - break; + return res / currentOperand; default: throw new IllegalArgumentException("Invalid operator: " + currentOperator); } - return res; } - ///--- + ///--- ui methods + public void updateSpreadsheet() { + for (int r = 0; r < cells.length; r++) + for (int c = 0; c < cells[r].length; c++) + evaluateCell(r, c); + } public String toString() { StringBuilder sb = new StringBuilder(); -- 2.43.0 From e9a9ac55274527c1871488f2cd3bb80b1e65e420 Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 05:20:21 +0100 Subject: [PATCH 09/31] Spreadsheet evaluateCell further implementation. --- .../informatik/spreadsheet/Spreadsheet.java | 88 +++++++++++++++---- 1 file changed, 69 insertions(+), 19 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 94ddeb5..a606258 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -146,23 +146,50 @@ public class Spreadsheet { String formula = cells[row][col].getFormula(); String result = ""; + String substringStartCell1 = formula.substring(formula.length() - 6, formula.length() - 4); + String substringStart2 = formula.substring(formula.length() - 6, formula.length() - 3); + String substringEndCell = formula.substring(formula.length() - 3, formula.length() - 1); + + if (formula.startsWith("SUMME(")) // e.g. SUMME(A3:A8) if(formula.length()<13) - result = "" + sum(formula.substring(6, 8), formula.substring(9, 11)); - else if(formula.length()<14&&formula.substring(6, 9).contains(":")) - result = "" + sum(formula.substring(6, 8), formula.substring(9, 12)); - else if(formula.length()<14&&!formula.substring(6, 9).contains(":")) - result = "" + sum(formula.substring(6, 9), formula.substring(10, 12)); + result = "" + sum(substringStartCell1, substringEndCell); + else if(formula.length()<14&&substringStart2.contains(":")) + result = "" + sum(substringStartCell1, substringEndCell); + else if(formula.length()<14&&!substringStart2.contains(":")) + result = "" + sum(substringStart2, substringEndCell); else if(formula.length()<15) - result = "" + sum(formula.substring(6, 9), formula.substring(10, 13)); + result = "" + sum(substringStart2, substringEndCell); else result = "0"; else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) - result = "TODO"; // TODO + if(formula.length()<15) + result = "" + product(substringStartCell1, substringEndCell); + else if(formula.length()<16&&substringStart2.contains(":")) + result = "" + product(substringStartCell1, substringEndCell); + else if(formula.length()<16&&!substringStart2.contains(":")) + result = "" + product(substringStart2, substringEndCell); + else if(formula.length()<17) + result = "" + product(substringStart2, substringEndCell); + else + result = "0"; + + else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) - result = "TODO"; // TODO + if(formula.length()<17) + result = "" + average(substringStartCell1, substringEndCell); + else if(formula.length()<18&&substringStart2.contains(":")) + result = "" + average(substringStartCell1, substringEndCell); + else if(formula.length()<18&&!substringStart2.contains(":")) + result = "" + average(substringStart2, substringEndCell); + else if(formula.length()<19) + result = "" + average(substringStart2, substringEndCell); + else + result = "0"; + + 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 @@ -198,6 +225,29 @@ public class Spreadsheet { return result; } + private long product(String startCellName, String endCellName) { + long result = Long.parseLong(cells[0][0].getValue());; + + for(int r = getRow(startCellName); r Date: Tue, 26 Dec 2023 05:40:50 +0100 Subject: [PATCH 10/31] Spreadsheet standardDeviation start of implementation. --- .../informatik/spreadsheet/Spreadsheet.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index a606258..eae19ed 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -54,6 +54,10 @@ public class Spreadsheet { return get(getRow(cellName), getCol(cellName)); } + public String getCellName(int row, int col) { + return "" + ((char) ('A' + col)) + (row+1); + } + private void put(int row, int col, String value) { if (!value.startsWith("=")) cells[row][col].setValue(value); @@ -248,6 +252,21 @@ public class Spreadsheet { result /= counter; return result; } + private double standardDeviation(String startCellName, String endCellName){ + ArrayList cellNames = new ArrayList<>(); + + long avg = 0; + int counter = 0; + for(int r = getRow(startCellName); r Date: Tue, 26 Dec 2023 05:46:30 +0100 Subject: [PATCH 11/31] Spreadsheet standardDeviation done. --- .../informatik/spreadsheet/Spreadsheet.java | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index eae19ed..68dc7c5 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -5,6 +5,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -195,7 +196,18 @@ public class Spreadsheet { else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung - result = "TODO"; // TODO + if(formula.length()<13) + result = "" + standardDeviation(substringStartCell1, substringEndCell); + else if(formula.length()<14&&substringStart2.contains(":")) + result = "" + standardDeviation(substringStartCell1, substringEndCell); + else if(formula.length()<14&&!substringStart2.contains(":")) + result = "" + standardDeviation(substringStart2, substringEndCell); + else if(formula.length()<15) + result = "" + standardDeviation(substringStart2, substringEndCell); + else + result = "0"; + + 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 @@ -265,7 +277,58 @@ public class Spreadsheet { cellNames.add(getCellName(r, c)); } catch (NumberFormatException n){} avg /= counter; - return 0; + //average + + ArrayList copyCellNames = new ArrayList<>(cellNames); + double[] frequency = new double[cellNames.size()]; + Arrays.fill(frequency,1); + ArrayList relativeFrequency = new ArrayList<>(); + double mem = 0; + + for(int i = 0; i< cellNames.size(); i++) { + for(int t = 0; t Date: Tue, 26 Dec 2023 06:34:14 +0100 Subject: [PATCH 12/31] Minor fixes and changes. --- .../informatik/spreadsheet/Axel.java | 21 +- .../informatik/spreadsheet/Spreadsheet.java | 179 ++++++++++++------ 2 files changed, 129 insertions(+), 71 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index 41c5da2..39d4cdf 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -1,6 +1,7 @@ package de.hs_mannheim.informatik.spreadsheet; import java.io.FileNotFoundException; +import java.util.Scanner; /** * Part of a simplified spreadsheet system for the PR1 programming lab at Hochschule Mannheim. @@ -10,16 +11,20 @@ import java.io.FileNotFoundException; public class Axel { public static void main(String[] args) throws FileNotFoundException { - Spreadsheet spr = new Spreadsheet(10,10); + Spreadsheet spr = new Spreadsheet(10, 10); + Scanner sc = new Scanner(System.in); - spr.cells[2][7].setFormula("=5+3"); - spr.updateSpreadsheet(); + while (true) { - - System.out.println(spr); - - // TODO: You might want to put "UI loop" for entering value and formulas here resp. in some UI methods. + spr.cells[sc.nextInt()-1][5].setFormula(sc.next()); + spr.updateSpreadsheet(); + + + System.out.println(spr); + + + // TODO: You might want to put "UI loop" for entering value and formulas here resp. in some UI methods. + } } - } \ No newline at end of file diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 68dc7c5..b86d043 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -151,67 +151,89 @@ public class Spreadsheet { String formula = cells[row][col].getFormula(); String result = ""; - String substringStartCell1 = formula.substring(formula.length() - 6, formula.length() - 4); - String substringStart2 = formula.substring(formula.length() - 6, formula.length() - 3); - String substringEndCell = formula.substring(formula.length() - 3, formula.length() - 1); + if(formula.length()>10) { + String substringStartCell1 = formula.substring(formula.length() - 6, formula.length() - 4); + String substringStart2 = formula.substring(formula.length() - 6, formula.length() - 3); + String substringEndCell = formula.substring(formula.length() - 3, formula.length() - 1); + + if (formula.startsWith("SUMME(")) // e.g. SUMME(A3:A8) + if (formula.length() < 13) + result = "" + sum(substringStartCell1, substringEndCell); + else if (formula.length() < 14 && substringStart2.contains(":")) + result = "" + sum(substringStartCell1, substringEndCell); + else if (formula.length() < 14 && !substringStart2.contains(":")) + result = "" + sum(substringStart2, substringEndCell); + else if (formula.length() < 15) + result = "" + sum(substringStart2, substringEndCell); + else + result = "0"; - if (formula.startsWith("SUMME(")) // e.g. SUMME(A3:A8) - if(formula.length()<13) - result = "" + sum(substringStartCell1, substringEndCell); - else if(formula.length()<14&&substringStart2.contains(":")) - result = "" + sum(substringStartCell1, substringEndCell); - else if(formula.length()<14&&!substringStart2.contains(":")) - result = "" + sum(substringStart2, substringEndCell); - else if(formula.length()<15) - result = "" + sum(substringStart2, substringEndCell); - else - result = "0"; + else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) + if (formula.length() < 15) + result = "" + product(substringStartCell1, substringEndCell); + else if (formula.length() < 16 && substringStart2.contains(":")) + result = "" + product(substringStartCell1, substringEndCell); + else if (formula.length() < 16 && !substringStart2.contains(":")) + result = "" + product(substringStart2, substringEndCell); + else if (formula.length() < 17) + result = "" + product(substringStart2, substringEndCell); + else + result = "0"; - else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) - if(formula.length()<15) - result = "" + product(substringStartCell1, substringEndCell); - else if(formula.length()<16&&substringStart2.contains(":")) - result = "" + product(substringStartCell1, substringEndCell); - else if(formula.length()<16&&!substringStart2.contains(":")) - result = "" + product(substringStart2, substringEndCell); - else if(formula.length()<17) - result = "" + product(substringStart2, substringEndCell); - else - result = "0"; + else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) + if (formula.length() < 17) + result = "" + average(substringStartCell1, substringEndCell); + else if (formula.length() < 18 && substringStart2.contains(":")) + result = "" + average(substringStartCell1, substringEndCell); + else if (formula.length() < 18 && !substringStart2.contains(":")) + result = "" + average(substringStart2, substringEndCell); + else if (formula.length() < 19) + result = "" + average(substringStart2, substringEndCell); + else + result = "0"; - else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) - if(formula.length()<17) - result = "" + average(substringStartCell1, substringEndCell); - else if(formula.length()<18&&substringStart2.contains(":")) - result = "" + average(substringStartCell1, substringEndCell); - else if(formula.length()<18&&!substringStart2.contains(":")) - result = "" + average(substringStart2, substringEndCell); - else if(formula.length()<19) - result = "" + average(substringStart2, substringEndCell); - else - result = "0"; + else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung + if (formula.length() < 13) + result = "" + standardDeviation(substringStartCell1, substringEndCell); + else if (formula.length() < 14 && substringStart2.contains(":")) + result = "" + standardDeviation(substringStartCell1, substringEndCell); + else if (formula.length() < 14 && !substringStart2.contains(":")) + result = "" + standardDeviation(substringStart2, substringEndCell); + else if (formula.length() < 15) + result = "" + standardDeviation(substringStart2, substringEndCell); + else + result = "0"; - else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung - if(formula.length()<13) - result = "" + standardDeviation(substringStartCell1, substringEndCell); - else if(formula.length()<14&&substringStart2.contains(":")) - result = "" + standardDeviation(substringStartCell1, substringEndCell); - else if(formula.length()<14&&!substringStart2.contains(":")) - result = "" + standardDeviation(substringStart2, substringEndCell); - else if(formula.length()<15) - result = "" + standardDeviation(substringStart2, substringEndCell); - else - result = "0"; + else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> kleinster Wert + if (formula.length() < 11) + result = "" + min(substringStartCell1, substringEndCell); + else if (formula.length() < 12 && substringStart2.contains(":")) + result = "" + min(substringStartCell1, substringEndCell); + else if (formula.length() < 12 && !substringStart2.contains(":")) + result = "" + min(substringStart2, substringEndCell); + else if (formula.length() < 13) + result = "" + min(substringStart2, substringEndCell); + else + result = "0"; - 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 + else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> größter Wert + if (formula.length() < 11) + result = "" + max(substringStartCell1, substringEndCell); + else if (formula.length() < 12 && substringStart2.contains(":")) + result = "" + max(substringStartCell1, substringEndCell); + else if (formula.length() < 12 && !substringStart2.contains(":")) + result = "" + max(substringStart2, substringEndCell); + else if (formula.length() < 13) + result = "" + max(substringStart2, substringEndCell); + else + result = "0"; + } + else if (!formula.isEmpty()) { try { result = "" + calculate(formula); @@ -252,8 +274,8 @@ public class Spreadsheet { return result; } - private long average(String startCellName, String endCellName){ - long result = 0; + private double average(String startCellName, String endCellName){ + double result = 0; int counter = 0; for(int r = getRow(startCellName); r copyCellNames = new ArrayList<>(cellNames); double[] frequency = new double[cellNames.size()]; @@ -330,6 +351,38 @@ public class Spreadsheet { return Math.sqrt(mem); //standardDeviation formula } + private long min(String startCellName, String endCellName){ + ArrayList cellNames = new ArrayList<>(); + + for(int r = getRow(startCellName); rLong.parseLong(get(cellNames.get(i)))) + result = Long.parseLong(get(cellNames.get(i))); + + return result; + } + private long max(String startCellName, String endCellName){ + ArrayList cellNames = new ArrayList<>(); + + for(int r = getRow(startCellName); r Date: Tue, 26 Dec 2023 09:59:16 +0100 Subject: [PATCH 13/31] Many fixes until excluding average method. --- .../informatik/spreadsheet/Axel.java | 3 +- .../informatik/spreadsheet/Spreadsheet.java | 178 ++++++++++-------- 2 files changed, 103 insertions(+), 78 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index 39d4cdf..bdb2500 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -20,8 +20,9 @@ public class Axel { spr.cells[sc.nextInt()-1][5].setFormula(sc.next()); spr.updateSpreadsheet(); - + System.out.println(spr.toStringShowFormula()); System.out.println(spr); + System.out.println(spr.cells[0][5]); // TODO: You might want to put "UI loop" for entering value and formulas here resp. in some UI methods. diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index b86d043..83aa9d3 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -56,7 +56,7 @@ public class Spreadsheet { } public String getCellName(int row, int col) { - return "" + ((char) ('A' + col)) + (row+1); + return ("" + ((char) ('A' + col))) + (row+1); } private void put(int row, int col, String value) { @@ -79,7 +79,7 @@ public class Spreadsheet { private int getRow(String cellName) { if(cellName.length()>2) - return Integer.parseInt(""+cellName.charAt(1)+cellName.charAt(2)) - 1; + return Integer.parseInt(""+cellName.charAt(1) + cellName.charAt(2)); return cellName.charAt(1) - '1'; } @@ -91,7 +91,7 @@ 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 starCellName The upper left cell where data from the CSV file should be inserted. + * @param startCellName The upper left cell where data from the CSV file should be inserted. * @return Nothing. * @throws IOException If path does not exist. */ @@ -144,7 +144,7 @@ public class Spreadsheet { /** * This method does the actual evaluation/calcluation of a specific cell * - * @param cellName the name of the cell to be evaluated + * @param row,col the name of row and column of the cell * @return Nothing. */ private void evaluateCell(int row, int col) { @@ -153,83 +153,73 @@ public class Spreadsheet { if(formula.length()>10) { String substringStartCell1 = formula.substring(formula.length() - 6, formula.length() - 4); - String substringStart2 = formula.substring(formula.length() - 6, formula.length() - 3); - String substringEndCell = formula.substring(formula.length() - 3, formula.length() - 1); + String substringStartCell2 = formula.substring(formula.length() - 7, formula.length() - 5); + String substringStartCell3 = formula.substring(formula.length() - 8, formula.length() - 5); + String substringEndCell1 = formula.substring(formula.length() - 3, formula.length() - 1); + String substringEndCell2 = formula.substring(formula.length() - 4, formula.length() - 1); - if (formula.startsWith("SUMME(")) // e.g. SUMME(A3:A8) + if (formula.startsWith("SUMME("))// e.g. SUMME(A3:A8) if (formula.length() < 13) - result = "" + sum(substringStartCell1, substringEndCell); - else if (formula.length() < 14 && substringStart2.contains(":")) - result = "" + sum(substringStartCell1, substringEndCell); - else if (formula.length() < 14 && !substringStart2.contains(":")) - result = "" + sum(substringStart2, substringEndCell); + result = "" + sum(substringStartCell1, substringEndCell1); + else if (formula.length() < 14) + result = "" + sum(substringStartCell2, substringEndCell2); else if (formula.length() < 15) - result = "" + sum(substringStart2, substringEndCell); + result = "" + sum(substringStartCell3, substringEndCell2); else result = "0"; else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) if (formula.length() < 15) - result = "" + product(substringStartCell1, substringEndCell); - else if (formula.length() < 16 && substringStart2.contains(":")) - result = "" + product(substringStartCell1, substringEndCell); - else if (formula.length() < 16 && !substringStart2.contains(":")) - result = "" + product(substringStart2, substringEndCell); + result = "" + product(substringStartCell1, substringEndCell1); + else if (formula.length() < 16 && !substringEndCell2.contains(":")) + result = "" + product(substringStartCell2, substringEndCell2); else if (formula.length() < 17) - result = "" + product(substringStart2, substringEndCell); + result = "" + product(substringStartCell3, substringEndCell2); else result = "0"; else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) if (formula.length() < 17) - result = "" + average(substringStartCell1, substringEndCell); - else if (formula.length() < 18 && substringStart2.contains(":")) - result = "" + average(substringStartCell1, substringEndCell); - else if (formula.length() < 18 && !substringStart2.contains(":")) - result = "" + average(substringStart2, substringEndCell); + result = "" + average(substringStartCell1, substringEndCell1); + else if (formula.length() < 18) + result = "" + average(substringStartCell2, substringEndCell2); else if (formula.length() < 19) - result = "" + average(substringStart2, substringEndCell); + result = "" + average(substringStartCell3, substringEndCell2); else result = "0"; else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung if (formula.length() < 13) - result = "" + standardDeviation(substringStartCell1, substringEndCell); - else if (formula.length() < 14 && substringStart2.contains(":")) - result = "" + standardDeviation(substringStartCell1, substringEndCell); - else if (formula.length() < 14 && !substringStart2.contains(":")) - result = "" + standardDeviation(substringStart2, substringEndCell); + result = "" + standardDeviation(substringStartCell1, substringEndCell1); + else if (formula.length() < 14) + result = "" + standardDeviation(substringStartCell2, substringEndCell2); else if (formula.length() < 15) - result = "" + standardDeviation(substringStart2, substringEndCell); + result = "" + standardDeviation(substringStartCell3, substringEndCell2); else result = "0"; - else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> kleinster Wert + else if (formula.startsWith("MIN(")) // e.g. MIN(C1:H13) -> kleinster Wert if (formula.length() < 11) - result = "" + min(substringStartCell1, substringEndCell); - else if (formula.length() < 12 && substringStart2.contains(":")) - result = "" + min(substringStartCell1, substringEndCell); - else if (formula.length() < 12 && !substringStart2.contains(":")) - result = "" + min(substringStart2, substringEndCell); + result = "" + min(substringStartCell1, substringEndCell1); + else if (formula.length() < 12) + result = "" + min(substringStartCell2, substringEndCell2); else if (formula.length() < 13) - result = "" + min(substringStart2, substringEndCell); + result = "" + min(substringStartCell3, substringEndCell2); else result = "0"; else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> größter Wert if (formula.length() < 11) - result = "" + max(substringStartCell1, substringEndCell); - else if (formula.length() < 12 && substringStart2.contains(":")) - result = "" + max(substringStartCell1, substringEndCell); - else if (formula.length() < 12 && !substringStart2.contains(":")) - result = "" + max(substringStart2, substringEndCell); + result = "" + max(substringStartCell1, substringEndCell1); + else if (formula.length() < 12) + result = "" + max(substringStartCell2, substringEndCell2); else if (formula.length() < 13) - result = "" + max(substringStart2, substringEndCell); + result = "" + max(substringStartCell3, substringEndCell2); else result = "0"; } @@ -259,22 +249,28 @@ public class Spreadsheet { for(int c = getCol(startCellName); c0) + result *= Long.parseLong(cells[r][c].getValue()); + else { + result = Long.parseLong(cells[r][c].getValue()); + counter++; + } + } catch (NumberFormatException | ArrayIndexOutOfBoundsException a ){} return result; } - private double average(String startCellName, String endCellName){ + private double average(String startCellName, String endCellName) { double result = 0; int counter = 0; for(int r = getRow(startCellName); r cellNames = new ArrayList<>(); - long avg = 0; + double avg = 0; int counter = 0; - for(int r = getRow(startCellName); r copyCellNames = new ArrayList<>(cellNames); double[] frequency = new double[cellNames.size()]; Arrays.fill(frequency,1); @@ -308,19 +305,7 @@ public class Spreadsheet { for(int i = 0; i< cellNames.size(); i++) { for(int t = 0; t13) + sb.append(" " + String.format("%13s", cells[r][c].getValue()).substring(0,13) + " |"); + else + sb.append(" " + String.format("%13s", cells[r][c].getValue()) + " |"); + } + + } + sb.append(System.lineSeparator()); + for (int i = 0; i < cells[0].length; i++) { + sb.append("----------------"); + } + sb.append("------"); + sb.append(System.lineSeparator()); + return sb.toString(); + + + } + public String toStringShowFormula() { + StringBuilder sb = new StringBuilder(); + + sb.append(System.lineSeparator()); + sb.append(" |"); + for (int i = 0; i < cells[0].length; i++) { + sb.append(" " + (char) ('A' + i) + " |"); + } + int rc = 1; + for (int r = 0; r < cells.length; r++) { + sb.append(System.lineSeparator()); + for (int i = 0; i < cells[0].length; i++) { + sb.append("----------------"); + } + sb.append("------"); + sb.append(System.lineSeparator()); + sb.append(String.format(" " + "%2s", rc++) + " |"); + + for (int c = 0; c < cells[r].length; c++) { + if((cells[r][c].getFormula()).length()>13) + sb.append(" " + String.format("%13s", cells[r][c].getFormula()).substring(0,13) + " |"); + else + sb.append(" " + String.format("%13s", cells[r][c].getFormula()) + " |"); } } -- 2.43.0 From 5fbf2658d49fc98f7c5f4f72f162f6e7312ddfbb Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 17:40:50 +0100 Subject: [PATCH 14/31] Spreadsheet calculate/evaluateCell method fix. --- .../informatik/spreadsheet/Axel.java | 1 - .../informatik/spreadsheet/Spreadsheet.java | 152 +++++++++--------- 2 files changed, 79 insertions(+), 74 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index bdb2500..fb7971b 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -22,7 +22,6 @@ public class Axel { System.out.println(spr.toStringShowFormula()); System.out.println(spr); - System.out.println(spr.cells[0][5]); // TODO: You might want to put "UI loop" for entering value and formulas here resp. in some UI methods. diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 83aa9d3..3149129 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -150,80 +150,86 @@ public class Spreadsheet { private void evaluateCell(int row, int col) { String formula = cells[row][col].getFormula(); String result = ""; + String substringStartCell1 = ""; + String substringStartCell2 = ""; + String substringStartCell3 = ""; + String substringEndCell1 = ""; + String substringEndCell2 = ""; if(formula.length()>10) { - String substringStartCell1 = formula.substring(formula.length() - 6, formula.length() - 4); - String substringStartCell2 = formula.substring(formula.length() - 7, formula.length() - 5); - String substringStartCell3 = formula.substring(formula.length() - 8, formula.length() - 5); - String substringEndCell1 = formula.substring(formula.length() - 3, formula.length() - 1); - String substringEndCell2 = formula.substring(formula.length() - 4, formula.length() - 1); - - if (formula.startsWith("SUMME("))// e.g. SUMME(A3:A8) - if (formula.length() < 13) - result = "" + sum(substringStartCell1, substringEndCell1); - else if (formula.length() < 14) - result = "" + sum(substringStartCell2, substringEndCell2); - else if (formula.length() < 15) - result = "" + sum(substringStartCell3, substringEndCell2); - else - result = "0"; - - - else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) - if (formula.length() < 15) - result = "" + product(substringStartCell1, substringEndCell1); - else if (formula.length() < 16 && !substringEndCell2.contains(":")) - result = "" + product(substringStartCell2, substringEndCell2); - else if (formula.length() < 17) - result = "" + product(substringStartCell3, substringEndCell2); - else - result = "0"; - - - else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) - if (formula.length() < 17) - result = "" + average(substringStartCell1, substringEndCell1); - else if (formula.length() < 18) - result = "" + average(substringStartCell2, substringEndCell2); - else if (formula.length() < 19) - result = "" + average(substringStartCell3, substringEndCell2); - else - result = "0"; - - - else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung - if (formula.length() < 13) - result = "" + standardDeviation(substringStartCell1, substringEndCell1); - else if (formula.length() < 14) - result = "" + standardDeviation(substringStartCell2, substringEndCell2); - else if (formula.length() < 15) - result = "" + standardDeviation(substringStartCell3, substringEndCell2); - else - result = "0"; - - - else if (formula.startsWith("MIN(")) // e.g. MIN(C1:H13) -> kleinster Wert - if (formula.length() < 11) - result = "" + min(substringStartCell1, substringEndCell1); - else if (formula.length() < 12) - result = "" + min(substringStartCell2, substringEndCell2); - else if (formula.length() < 13) - result = "" + min(substringStartCell3, substringEndCell2); - else - result = "0"; - - - else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> größter Wert - if (formula.length() < 11) - result = "" + max(substringStartCell1, substringEndCell1); - else if (formula.length() < 12) - result = "" + max(substringStartCell2, substringEndCell2); - else if (formula.length() < 13) - result = "" + max(substringStartCell3, substringEndCell2); - else - result = "0"; + substringStartCell1 = formula.substring(formula.length() - 6, formula.length() - 4); + substringStartCell2 = formula.substring(formula.length() - 7, formula.length() - 5); + substringStartCell3 = formula.substring(formula.length() - 8, formula.length() - 5); + substringEndCell1 = formula.substring(formula.length() - 3, formula.length() - 1); + substringEndCell2 = formula.substring(formula.length() - 4, formula.length() - 1); } + if (formula.startsWith("SUMME("))// e.g. SUMME(A3:A8) + if (formula.length() < 13) + result = "" + sum(substringStartCell1, substringEndCell1); + else if (formula.length() < 14) + result = "" + sum(substringStartCell2, substringEndCell2); + else if (formula.length() < 15) + result = "" + sum(substringStartCell3, substringEndCell2); + else + result = "0"; + + + else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) + if (formula.length() < 15) + result = "" + product(substringStartCell1, substringEndCell1); + else if (formula.length() < 16 && !substringEndCell2.contains(":")) + result = "" + product(substringStartCell2, substringEndCell2); + else if (formula.length() < 17) + result = "" + product(substringStartCell3, substringEndCell2); + else + result = "0"; + + + else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) + if (formula.length() < 17) + result = "" + average(substringStartCell1, substringEndCell1); + else if (formula.length() < 18) + result = "" + average(substringStartCell2, substringEndCell2); + else if (formula.length() < 19) + result = "" + average(substringStartCell3, substringEndCell2); + else + result = "0"; + + + else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung + if (formula.length() < 13) + result = "" + standardDeviation(substringStartCell1, substringEndCell1); + else if (formula.length() < 14) + result = "" + standardDeviation(substringStartCell2, substringEndCell2); + else if (formula.length() < 15) + result = "" + standardDeviation(substringStartCell3, substringEndCell2); + else + result = "0"; + + + else if (formula.startsWith("MIN(")) // e.g. MIN(C1:H13) -> kleinster Wert + if (formula.length() < 11) + result = "" + min(substringStartCell1, substringEndCell1); + else if (formula.length() < 12) + result = "" + min(substringStartCell2, substringEndCell2); + else if (formula.length() < 13) + result = "" + min(substringStartCell3, substringEndCell2); + else + result = "0"; + + + else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> größter Wert + if (formula.length() < 11) + result = "" + max(substringStartCell1, substringEndCell1); + else if (formula.length() < 12) + result = "" + max(substringStartCell2, substringEndCell2); + else if (formula.length() < 13) + result = "" + max(substringStartCell3, substringEndCell2); + else + result = "0"; + + else if (!formula.isEmpty()) { try { result = "" + calculate(formula); @@ -380,7 +386,7 @@ public class Spreadsheet { * @return The result calculated. */ private long calculate(String formula) throws ArithmeticException { - Matcher m = Pattern.compile("([A-Z][0-9]*)|[-+*/]|[0-9]+").matcher(formula); + Matcher m = Pattern.compile("([A-Z][1-9][0-9]*)|[-+*/]|[0-9]+").matcher(formula); long result = 0; long currentOperand = 0; @@ -392,9 +398,9 @@ public class Spreadsheet { if (s.matches(("[0-9]+"))) currentOperand = Long.parseLong(s); - else if ((s.matches("[A-Z][1-9]*") || s.matches("[A-Z][1-9]*+")) && get(s).isEmpty()) + else if (s.matches("[A-Z][1-9][0-9]*") && get(s).isEmpty()) currentOperand = 0; - else if ((s.matches("[A-Z][1-9]*") || s.matches("[A-Z][1-9]*+"))) { + else if (s.matches("[A-Z][1-9][0-9]*")) { currentOperand = Long.parseLong(get(s)); } else { if (!firstOperator) { -- 2.43.0 From dd9ff48a4e090273859d60760683b7003ed49b22 Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 18:04:38 +0100 Subject: [PATCH 15/31] Spreadsheet evaluateCell average fix. --- .../de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 3149129..435847d 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -187,11 +187,11 @@ public class Spreadsheet { else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) - if (formula.length() < 17) + if (formula.length() < 18) result = "" + average(substringStartCell1, substringEndCell1); - else if (formula.length() < 18) - result = "" + average(substringStartCell2, substringEndCell2); else if (formula.length() < 19) + result = "" + average(substringStartCell2, substringEndCell2); + else if (formula.length() < 20) result = "" + average(substringStartCell3, substringEndCell2); else result = "0"; -- 2.43.0 From 6e59545dc123003194a69df64256aa4b6e81b97c Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 18:15:27 +0100 Subject: [PATCH 16/31] Spreadsheet standardDeviation fix. --- .../hs_mannheim/informatik/spreadsheet/Spreadsheet.java | 8 ++++---- 1 file changed, 4 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 435847d..67664db 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -293,13 +293,13 @@ public class Spreadsheet { double avg = 0; int counter = 0; - for(int r = getRow(startCellName); r Date: Tue, 26 Dec 2023 19:13:33 +0100 Subject: [PATCH 17/31] Spreadsheet evaluateCell functions fixes. --- .../informatik/spreadsheet/Spreadsheet.java | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 67664db..32f00bb 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -74,13 +74,13 @@ public class Spreadsheet { } private int getCol(String cellName) { - return cellName.charAt(0) - 'A'; + return cellName.charAt(0) - 'A' + 1; } private int getRow(String cellName) { if(cellName.length()>2) return Integer.parseInt(""+cellName.charAt(1) + cellName.charAt(2)); - return cellName.charAt(1) - '1'; + return cellName.charAt(1) - '1' + 1; } // ----- @@ -156,7 +156,7 @@ public class Spreadsheet { String substringEndCell1 = ""; String substringEndCell2 = ""; - if(formula.length()>10) { + if(formula.length()>9) { substringStartCell1 = formula.substring(formula.length() - 6, formula.length() - 4); substringStartCell2 = formula.substring(formula.length() - 7, formula.length() - 5); substringStartCell3 = formula.substring(formula.length() - 8, formula.length() - 5); @@ -251,11 +251,10 @@ public class Spreadsheet { private long sum(String startCellName, String endCellName) { long result = 0; - for(int r = getRow(startCellName); r0) result *= Long.parseLong(cells[r][c].getValue()); else { result = Long.parseLong(cells[r][c].getValue()); counter++; } - } catch (NumberFormatException | ArrayIndexOutOfBoundsException a ){} return result; } private double average(String startCellName, String endCellName) { double result = 0; int counter = 0; - for(int r = getRow(startCellName); r copyCellNames = new ArrayList<>(cellNames); double[] frequency = new double[cellNames.size()]; Arrays.fill(frequency,1); @@ -323,7 +321,7 @@ public class Spreadsheet { for(int i = 0; i< cellNames.size(); i++) relativeFrequency.add(i,frequency[i]/copyCellNames.size()); - System.out.println("CellNames: "+cellNames); + if(get(cellNames.get(0)).isEmpty()) mem = ((0 - avg)*(0 - avg)) * relativeFrequency.get(0); @@ -345,32 +343,34 @@ public class Spreadsheet { private long min(String startCellName, String endCellName){ ArrayList cellNames = new ArrayList<>(); - for(int r = getRow(startCellName); rLong.parseLong(get(cellNames.get(i)))) - result = Long.parseLong(get(cellNames.get(i))); - + try { + if (result > Long.parseLong(get(cellNames.get(i)))) + result = Long.parseLong(get(cellNames.get(i))); + } catch(NumberFormatException n){} return result; } private long max(String startCellName, String endCellName){ ArrayList cellNames = new ArrayList<>(); - for(int r = getRow(startCellName); r Date: Wed, 27 Dec 2023 02:55:18 +0100 Subject: [PATCH 18/31] Spreadsheet getRow/getCol and more function fixes. --- .../informatik/spreadsheet/Spreadsheet.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 32f00bb..416e81a 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -52,7 +52,7 @@ public class Spreadsheet { public String get(String cellName) { cellName = cellName.toUpperCase(); - return get(getRow(cellName), getCol(cellName)); + return get(getRow(cellName)-1, getCol(cellName)-1); } public String getCellName(int row, int col) { @@ -70,7 +70,7 @@ public class Spreadsheet { public void put(String cellName, String value) { cellName = cellName.toUpperCase(); - put(getRow(cellName), getCol(cellName), value); + put(getRow(cellName)-1, getCol(cellName)-1, value); } private int getCol(String cellName) { @@ -306,10 +306,10 @@ public class Spreadsheet { Arrays.fill(frequency,1); ArrayList relativeFrequency = new ArrayList<>(); double mem = 0; - + System.out.println(cellNames); for(int i = 0; i< cellNames.size(); i++) { for(int t = 0; t Date: Wed, 27 Dec 2023 03:29:44 +0100 Subject: [PATCH 19/31] Spreadsheet changed every function supporting double. --- .../informatik/spreadsheet/Spreadsheet.java | 99 ++++++++++--------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 416e81a..256189b 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -149,7 +149,7 @@ public class Spreadsheet { */ private void evaluateCell(int row, int col) { String formula = cells[row][col].getFormula(); - String result = ""; + double result = 0; String substringStartCell1 = ""; String substringStartCell2 = ""; String substringStartCell3 = ""; @@ -166,79 +166,80 @@ public class Spreadsheet { if (formula.startsWith("SUMME("))// e.g. SUMME(A3:A8) if (formula.length() < 13) - result = "" + sum(substringStartCell1, substringEndCell1); + result = sum(substringStartCell1, substringEndCell1); else if (formula.length() < 14) - result = "" + sum(substringStartCell2, substringEndCell2); + result = sum(substringStartCell2, substringEndCell2); else if (formula.length() < 15) - result = "" + sum(substringStartCell3, substringEndCell2); + result = sum(substringStartCell3, substringEndCell2); else - result = "0"; + result = 0; else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9) if (formula.length() < 15) - result = "" + product(substringStartCell1, substringEndCell1); + result = product(substringStartCell1, substringEndCell1); else if (formula.length() < 16 && !substringEndCell2.contains(":")) - result = "" + product(substringStartCell2, substringEndCell2); + result = product(substringStartCell2, substringEndCell2); else if (formula.length() < 17) - result = "" + product(substringStartCell3, substringEndCell2); + result = product(substringStartCell3, substringEndCell2); else - result = "0"; + result = 0; else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) if (formula.length() < 18) - result = "" + average(substringStartCell1, substringEndCell1); + result = average(substringStartCell1, substringEndCell1); else if (formula.length() < 19) - result = "" + average(substringStartCell2, substringEndCell2); + result = average(substringStartCell2, substringEndCell2); else if (formula.length() < 20) - result = "" + average(substringStartCell3, substringEndCell2); + result = average(substringStartCell3, substringEndCell2); else - result = "0"; + result = 0; else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung if (formula.length() < 13) - result = "" + standardDeviation(substringStartCell1, substringEndCell1); + result = standardDeviation(substringStartCell1, substringEndCell1); else if (formula.length() < 14) - result = "" + standardDeviation(substringStartCell2, substringEndCell2); + result = standardDeviation(substringStartCell2, substringEndCell2); else if (formula.length() < 15) - result = "" + standardDeviation(substringStartCell3, substringEndCell2); + result = standardDeviation(substringStartCell3, substringEndCell2); else - result = "0"; + result = 0; else if (formula.startsWith("MIN(")) // e.g. MIN(C1:H13) -> kleinster Wert if (formula.length() < 11) - result = "" + min(substringStartCell1, substringEndCell1); + result = min(substringStartCell1, substringEndCell1); else if (formula.length() < 12) - result = "" + min(substringStartCell2, substringEndCell2); + result = min(substringStartCell2, substringEndCell2); else if (formula.length() < 13) - result = "" + min(substringStartCell3, substringEndCell2); + result = min(substringStartCell3, substringEndCell2); else - result = "0"; + result = 0; else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> größter Wert if (formula.length() < 11) - result = "" + max(substringStartCell1, substringEndCell1); + result = max(substringStartCell1, substringEndCell1); else if (formula.length() < 12) - result = "" + max(substringStartCell2, substringEndCell2); + result = max(substringStartCell2, substringEndCell2); else if (formula.length() < 13) - result = "" + max(substringStartCell3, substringEndCell2); + result = max(substringStartCell3, substringEndCell2); else - result = "0"; + result = 0; else if (!formula.isEmpty()) { try { - result = "" + calculate(formula); + result = calculate(formula); } catch (ArithmeticException ae) { - result = "exc."; + result = 0; } } - cells[row][col].setValue(result); + if(!cells[row][col].getFormula().isEmpty()) + cells[row][col].setValue(String.format("%.1f",result)); } /** @@ -248,27 +249,27 @@ public class Spreadsheet { * @param endCellName The name of the cell in the lower right corner of the rectangle. * @return The sum calculated. */ - private long sum(String startCellName, String endCellName) { - long result = 0; + private double sum(String startCellName, String endCellName) { + double result = 0; for(int r = getRow(startCellName)-1; r0) - result *= Long.parseLong(cells[r][c].getValue()); + result *= Double.parseDouble(cells[r][c].getValue()); else { - result = Long.parseLong(cells[r][c].getValue()); + result = Double.parseDouble(cells[r][c].getValue()); counter++; } @@ -341,7 +342,7 @@ public class Spreadsheet { return Math.sqrt(mem); //standardDeviation formula } - private long min(String startCellName, String endCellName){ + private double min(String startCellName, String endCellName){ ArrayList cellNames = new ArrayList<>(); for(int r = getRow(startCellName)-1; r Long.parseLong(get(cellNames.get(i)))) - result = Long.parseLong(get(cellNames.get(i))); + if (result > Double.parseDouble(get(cellNames.get(i)))) + result = Double.parseDouble(get(cellNames.get(i))); } catch(NumberFormatException n){} return result; } - private long max(String startCellName, String endCellName){ + private double max(String startCellName, String endCellName){ ArrayList cellNames = new ArrayList<>(); for(int r = getRow(startCellName)-1; r Date: Wed, 27 Dec 2023 04:06:50 +0100 Subject: [PATCH 20/31] Spreadsheet new uiMethod cellInput implemented. --- .../informatik/spreadsheet/Axel.java | 4 --- .../informatik/spreadsheet/Spreadsheet.java | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index fb7971b..652fac5 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -16,10 +16,6 @@ public class Axel { while (true) { - - spr.cells[sc.nextInt()-1][5].setFormula(sc.next()); - spr.updateSpreadsheet(); - System.out.println(spr.toStringShowFormula()); System.out.println(spr); diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 256189b..6f2a3a7 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -443,6 +443,32 @@ public class Spreadsheet { for (int c = 0; c < cells[r].length; c++) evaluateCell(r, c); } + public void cellInput() throws FileNotFoundException { + Scanner cs = new Scanner(System.in); + + String input = cs.nextLine(); + ArrayList inputs = new ArrayList<>(); + inputs.add(input.split(" ")[0]); + inputs.add(input.split(" ")[1]); + + try { + if (inputs.contains("EINLESEN")) + readCsv(inputs.get(1).split(" ")[0], inputs.get(1).split(" ")[1].charAt(0), inputs.get(1).split(" ")[2]); + else if (inputs.contains("SPEICHERN")) + saveCsv(inputs.get(1)); + else if (inputs.contains("FORMELN")) + System.out.println(toStringShowFormula()); + else + cells[getRow(inputs.get(0)) - 1][getCol(inputs.get(1)) - 1].setFormula(cs.next()); + + updateSpreadsheet(); + } catch(ArrayIndexOutOfBoundsException a){ + System.out.println("\nEingegebene Zelle existiert nicht!"); + } + + inputs.clear(); + + } public String toString() { StringBuilder sb = new StringBuilder(); -- 2.43.0 From e3606f068b05521c409d81186537c3fb5b7a0110 Mon Sep 17 00:00:00 2001 From: selim Date: Wed, 27 Dec 2023 05:00:31 +0100 Subject: [PATCH 21/31] All ui methods implemented. --- .../informatik/spreadsheet/Axel.java | 20 +++++++++++++++---- .../informatik/spreadsheet/Spreadsheet.java | 20 ++++++++++++------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index 652fac5..e9c4e46 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -11,16 +11,28 @@ import java.util.Scanner; public class Axel { public static void main(String[] args) throws FileNotFoundException { - Spreadsheet spr = new Spreadsheet(10, 10); Scanner sc = new Scanner(System.in); + System.out.println("\nAxel(ExcelFakeVon2211482): "); + System.out.print("\nTabellengröße(ReihenZwischen1-99 SpaltenZwischen1-26): "); + Spreadsheet spr = new Spreadsheet(sc.nextInt(), sc.nextInt()); + String help = "n"; while (true) { - System.out.println(spr.toStringShowFormula()); System.out.println(spr); + System.out.println("\nHILFE (Für eine Anleitung.)\n"); + System.out.print("KOMMANDO: "); + spr.cellInput(); - - // TODO: You might want to put "UI loop" for entering value and formulas here resp. in some UI methods. } } + + public static void help(){ + System.out.println("\nEinlesen: \nKOMMANDO Dateipfad Trennzeichen StartzelleObenLinks (Alles mit Leerzeichen getrennt.) e.g.:\nEINLESEN Axel/resources/zahlen.csv , A1"); + System.out.println("\nSpeichern: \nKOMMANDO Dateipfad (Mit Leerzeichen getrennt.) e.g.:\nSPEICHERN Axel/resources/zahlen.csv"); + System.out.println("\nFormel Tabellenansicht: \nKOMMANDO e.g.:\nFORMELN"); + System.out.println("\nZellen Werte/Formeln zuweisen: \nZELLE ZUWEISUNG (Mit Leerzeichen getrennt, Zelle beginnend mit Buchstabe und Zuweisung beginnend mit =.) e.g.:\nA1 =A5+15\n" + + "\nZELLE FORMELZUWEISUNG (Formelzuweisung mit Startzelle bis Endzelle getrennt durch :.) e.g.:" + + "\nA2 =SUMME(A1:H10)\t\tA3 =PRODUKT(A1:H10)\t\tA4 =MITTELWERT(A1:H10)\t\tA5 =STABW(A1:H10) (Standartabweichung)\t\tA6 =MIN(A1:H10)\t\tA7 =MAX(A1:H10)"); + } } \ No newline at end of file diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 6f2a3a7..9551e5a 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -448,18 +448,22 @@ public class Spreadsheet { String input = cs.nextLine(); ArrayList inputs = new ArrayList<>(); - inputs.add(input.split(" ")[0]); - inputs.add(input.split(" ")[1]); + for(int i =0; i Date: Wed, 27 Dec 2023 06:02:19 +0100 Subject: [PATCH 22/31] First version: 1.0 finished. --- Axel/resources/zahlen.csv | 14 +++-- .../informatik/spreadsheet/Axel.java | 19 ++++--- .../informatik/spreadsheet/Spreadsheet.java | 51 +++++++++++-------- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/Axel/resources/zahlen.csv b/Axel/resources/zahlen.csv index 1ec60e0..6c59c73 100644 --- a/Axel/resources/zahlen.csv +++ b/Axel/resources/zahlen.csv @@ -1,4 +1,10 @@ -1,2 -3,4 -5,6 -7,8 +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index e9c4e46..e1be23a 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -15,14 +15,21 @@ public class Axel { System.out.println("\nAxel(ExcelFakeVon2211482): "); System.out.print("\nTabellengröße(ReihenZwischen1-99 SpaltenZwischen1-26): "); Spreadsheet spr = new Spreadsheet(sc.nextInt(), sc.nextInt()); - String help = "n"; + boolean stop = false; - while (true) { + while (!stop) { - System.out.println(spr); - System.out.println("\nHILFE (Für eine Anleitung.)\n"); - System.out.print("KOMMANDO: "); - spr.cellInput(); + try { + System.out.println(spr); + System.out.println("\nHILFE (Für eine Anleitung.)\n"); + System.out.print("KOMMANDO: "); + stop = spr.cellInput(); + } catch(Exception e){ + System.out.println("\nEingabe unzulässig!"); + System.out.println("\nEnter zum fortfahren."); + sc.nextLine(); + sc.nextLine(); + } } } diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 9551e5a..04222ee 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -107,8 +107,8 @@ public class Spreadsheet { for(int i = 0; i < memList.size(); i++) memArr[i] = (memList.get(i)).split(String.valueOf(separator)); - for (int r = getRow(startCellName); r < memList.size(); r++) - for (int c = getCol(startCellName); c < memList.get(0).length(); c++) + for (int r = getRow(startCellName)-1; r < memList.size(); r++) + for (int c = getCol(startCellName)-1; c < memList.get(0).length(); c++) if(c Date: Wed, 27 Dec 2023 06:06:45 +0100 Subject: [PATCH 23/31] Removed unnecessary outputs in method. --- .../de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java | 6 ++---- 1 file changed, 2 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 04222ee..52c027d 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -307,7 +307,7 @@ public class Spreadsheet { Arrays.fill(frequency,1); ArrayList relativeFrequency = new ArrayList<>(); double mem = 0; - System.out.println(cellNames); + for(int i = 0; i< cellNames.size(); i++) { for(int t = 0; t Date: Wed, 27 Dec 2023 17:42:22 +0100 Subject: [PATCH 24/31] Axel loop update fixes. --- Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java | 1 + .../de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index e1be23a..8524a11 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -20,6 +20,7 @@ public class Axel { while (!stop) { try { + spr.updateSpreadsheet(); System.out.println(spr); System.out.println("\nHILFE (Für eine Anleitung.)\n"); System.out.print("KOMMANDO: "); diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 52c027d..ee70b5e 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -281,7 +281,7 @@ public class Spreadsheet { for(int r = getRow(startCellName)-1; r Date: Wed, 27 Dec 2023 18:06:58 +0100 Subject: [PATCH 25/31] More error handling and loop improvements. --- .../informatik/spreadsheet/Axel.java | 23 +++++++++++++++---- .../informatik/spreadsheet/Spreadsheet.java | 11 ++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index 8524a11..f684c00 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -1,6 +1,7 @@ package de.hs_mannheim.informatik.spreadsheet; import java.io.FileNotFoundException; +import java.util.InputMismatchException; import java.util.Scanner; /** @@ -11,12 +12,24 @@ import java.util.Scanner; public class Axel { public static void main(String[] args) throws FileNotFoundException { - Scanner sc = new Scanner(System.in); - System.out.println("\nAxel(ExcelFakeVon2211482): "); - System.out.print("\nTabellengröße(ReihenZwischen1-99 SpaltenZwischen1-26): "); - Spreadsheet spr = new Spreadsheet(sc.nextInt(), sc.nextInt()); + Spreadsheet spr = new Spreadsheet(10,10); + boolean match = false; boolean stop = false; + Scanner sc = new Scanner(System.in); + System.out.println("\nAxel(ExcelFakeVon2211482): "); + while (!match) { + try { + System.out.print("\nTabellengröße(ReihenZwischen1-99 SpaltenZwischen1-26): "); + spr = new Spreadsheet(sc.nextInt(), sc.nextInt()); + match = true; + } catch(InputMismatchException i){ + System.out.println("\nGeben Sie zwei Ganzzahlen mit Leerzeichen dazwischen an!"); + System.out.println("\nEnter zum fortfahren."); + sc.nextLine(); + sc.nextLine(); + } + } while (!stop) { try { @@ -39,7 +52,7 @@ public class Axel { System.out.println("\nEinlesen: \nKOMMANDO Dateipfad Trennzeichen StartzelleObenLinks (Alles mit Leerzeichen getrennt.) e.g.:\nEINLESEN Axel/resources/zahlen.csv , A1"); System.out.println("\nSpeichern: \nKOMMANDO Dateipfad (Mit Leerzeichen getrennt.) e.g.:\nSPEICHERN Axel/resources/zahlen.csv"); System.out.println("\nFormel Tabellenansicht: \nKOMMANDO e.g.:\nFORMELN"); - System.out.println("\nZellen Werte/Formeln zuweisen: \nZELLE ZUWEISUNG (Mit Leerzeichen getrennt, Zelle beginnend mit Buchstabe und Zuweisung beginnend mit =.) e.g.:\nA1 =A5+15\n" + + System.out.println("\nZellen Werte/Formeln zuweisen: \nZELLE ZUWEISUNG (Mit Leerzeichen getrennt, Zelle beginnend mit Buchstabe und Zuweisung beginnend mit =; Keine Kommazahlen als Eingabe erlaubt.) e.g.:\nA1 =A5+15\n" + "\nZELLE FORMELZUWEISUNG (Formelzuweisung mit Startzelle bis Endzelle getrennt durch :.) e.g.:" + "\nA2 =SUMME(A1:H10)\t\tA3 =PRODUKT(A1:H10)\t\tA4 =MITTELWERT(A1:H10)\t\tA5 =STABW(A1:H10) (Standartabweichung)\t\tA6 =MIN(A1:H10)\t\tA7 =MAX(A1:H10)"); } diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index ee70b5e..d6771b6 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -284,7 +284,8 @@ public class Spreadsheet { result += Double.parseDouble(cells[r][c].getValue()); counter++; } - result /= counter; + if(result!=0) + result /= counter; return result; } private double standardDeviation(String startCellName, String endCellName){ @@ -302,6 +303,9 @@ public class Spreadsheet { avg /= counter; //average/ add cell names to list + if(cellNames.isEmpty()) + return 0; + ArrayList copyCellNames = new ArrayList<>(cellNames); double[] frequency = new double[cellNames.size()]; Arrays.fill(frequency,1); @@ -348,6 +352,9 @@ public class Spreadsheet { if(!cells[r][c].isEmpty()) cellNames.add(getCellName(r, c)); + if(cellNames.isEmpty()) + return 0; + double result = Double.parseDouble(get(cellNames.get(0))); for(int i = 0; i< cellNames.size(); i++) try { @@ -364,6 +371,8 @@ public class Spreadsheet { if(!cells[r][c].isEmpty()) cellNames.add(getCellName(r, c)); + if(cellNames.isEmpty()) + return 0; double result = Double.parseDouble(get(cellNames.get(0))); for(int i = 0; i< cellNames.size(); i++) -- 2.43.0 From 347d36a669067207831952ef72a3e0e592f1661f Mon Sep 17 00:00:00 2001 From: selim Date: Wed, 27 Dec 2023 19:14:30 +0100 Subject: [PATCH 26/31] Some method descriptions, toString/seeFormula updated, readCsv fix. --- Axel/resources/zahlen.csv | 19 ++- .../informatik/spreadsheet/Spreadsheet.java | 130 ++++++++++++++---- 2 files changed, 114 insertions(+), 35 deletions(-) diff --git a/Axel/resources/zahlen.csv b/Axel/resources/zahlen.csv index 6c59c73..9167e5d 100644 --- a/Axel/resources/zahlen.csv +++ b/Axel/resources/zahlen.csv @@ -1,10 +1,9 @@ -,,,,,,,,, -,,,,,,,,, -,,,,,,,,, -,,,,,,,,, -,,,,,,,,, -,,,,,,,,, -,,,,,,,,, -,,,,,,,,, -,,,,,,,,, -,,,,,,,,, +=2,,,=SUMME(A1:A6),,,,,,,, +,,,,,,,,,,, +,,,,,,,,,,, +,,,,,,,,,,, +,,,,,,,,,,, +,,,,,,,,,,, +,,,,,,,,,,, +,,,,,,,,,,, +,,,,,,,,,,, diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index d6771b6..de45b73 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -110,7 +110,7 @@ public class Spreadsheet { for (int r = getRow(startCellName)-1; r < memList.size(); r++) for (int c = getCol(startCellName)-1; c < memList.get(0).length(); c++) if(c cellNames = new ArrayList<>(); @@ -344,6 +376,14 @@ public class Spreadsheet { return Math.sqrt(mem); //standardDeviation formula } + + /** + * Method to find out the lowest number 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 lowest number. + */ private double min(String startCellName, String endCellName){ ArrayList cellNames = new ArrayList<>(); @@ -363,6 +403,14 @@ public class Spreadsheet { } catch(NumberFormatException n){} return result; } + + /** + * Method to find out the highest number 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 highest number. + */ private double max(String startCellName, String endCellName){ ArrayList cellNames = new ArrayList<>(); @@ -429,27 +477,49 @@ public class Spreadsheet { return result; } - private double evaluateOperator(double result, double currentOperand, String currentOperator) { + + /** + * This method does the actual calculation with the current operator, + * the left and right operands provided by the calculate method. + * + * @param leftOperand The first operand used to calculate. + * @param rightOperand The second operand used to calculate. + * @param currentOperator The current operator used to calculate. + * @return The partial result calculated. + */ + private double evaluateOperator(double leftOperand, double rightOperand, String currentOperator) { switch (currentOperator) { case "+": - return (result + currentOperand); + return (leftOperand + rightOperand); case "-": - return (result - currentOperand); + return (leftOperand - rightOperand); case "*": - return (result * currentOperand); + return (leftOperand * rightOperand); case "/": - return (result / currentOperand); + return (leftOperand / rightOperand); default: throw new IllegalArgumentException("Invalid operator: " + currentOperator); } } ///--- ui methods + + /** + * This method updates all cells value by provided formula. + * + * @return nothing. + */ public void updateSpreadsheet() { for (int r = 0; r < cells.length; r++) for (int c = 0; c < cells[r].length; c++) evaluateCell(r, c); } + + /** + * This method scans and evaluates the user input. + * + * @return The boolean true, when the programm is finished by the user input. + */ public boolean cellInput() throws FileNotFoundException { Scanner cs = new Scanner(System.in); @@ -491,36 +561,42 @@ public class Spreadsheet { inputs.clear(); return false; } + + /** + * This method outputs the cell spreadsheet with all the values. + * + * @return nothing. + */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append(System.lineSeparator()); sb.append(System.lineSeparator()); - sb.append(" |"); + sb.append(" |"); for (int i = 0; i < cells[0].length; i++) { - sb.append(" " + (char) ('A' + i) + " |"); + sb.append(" " + (char) ('A' + i) + " |"); } int rc = 1; for (int r = 0; r < cells.length; r++) { sb.append(System.lineSeparator()); for (int i = 0; i < cells[0].length; i++) { - sb.append("----------------"); + sb.append("----------------------"); } sb.append("------"); sb.append(System.lineSeparator()); - sb.append(String.format(" " + "%2s", rc++) + " |"); + sb.append(String.format(" " + "%2s", rc++) + " |"); for (int c = 0; c < cells[r].length; c++) { - if((cells[r][c].getValue()).length()>13) - sb.append(" " + String.format("%13s", cells[r][c].getValue()).substring(0,13) + " |"); + if((cells[r][c].getValue()).length()>19) + sb.append(" " + String.format("%19s", cells[r][c].getValue()).substring(0,19) + " |"); else - sb.append(" " + String.format("%13s", cells[r][c].getValue()) + " |"); + sb.append(" " + String.format("%19s", cells[r][c].getValue()) + " |"); } } sb.append(System.lineSeparator()); for (int i = 0; i < cells[0].length; i++) { - sb.append("----------------"); + sb.append("----------------------"); } sb.append("------"); sb.append(System.lineSeparator()); @@ -528,36 +604,40 @@ public class Spreadsheet { } + + + /** + * This method outputs the cell spreadsheet with all the formulas instead of the values. + * + * @return nothing. + */ public String toStringShowFormula() { StringBuilder sb = new StringBuilder(); sb.append(System.lineSeparator()); sb.append(System.lineSeparator()); - sb.append(" |"); + sb.append(" |"); for (int i = 0; i < cells[0].length; i++) { - sb.append(" " + (char) ('A' + i) + " |"); + sb.append(" " + (char) ('A' + i) + " |"); } int rc = 1; for (int r = 0; r < cells.length; r++) { sb.append(System.lineSeparator()); for (int i = 0; i < cells[0].length; i++) { - sb.append("----------------"); + sb.append("----------------------"); } sb.append("------"); sb.append(System.lineSeparator()); - sb.append(String.format(" " + "%2s", rc++) + " |"); + sb.append(String.format(" " + "%2s", rc++) + " |"); for (int c = 0; c < cells[r].length; c++) { - if((cells[r][c].getFormula()).length()>13) - sb.append(" " + String.format("%13s", cells[r][c].getFormula()).substring(0,13) + " |"); - else - sb.append(" " + String.format("%13s", cells[r][c].getFormula()) + " |"); + sb.append(" " + String.format("%19s", cells[r][c].getFormula()) + " |"); } } sb.append(System.lineSeparator()); for (int i = 0; i < cells[0].length; i++) { - sb.append("----------------"); + sb.append("----------------------"); } sb.append("------"); sb.append(System.lineSeparator()); @@ -565,4 +645,4 @@ public class Spreadsheet { } -} \ No newline at end of file +} -- 2.43.0 From fd91996029696a74f31f6dae63f0410916e2b2f2 Mon Sep 17 00:00:00 2001 From: selim Date: Wed, 27 Dec 2023 19:16:45 +0100 Subject: [PATCH 27/31] Ui methods category fix. --- .../de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index de45b73..7888480 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -502,8 +502,6 @@ public class Spreadsheet { } } - ///--- ui methods - /** * This method updates all cells value by provided formula. * @@ -515,6 +513,9 @@ public class Spreadsheet { evaluateCell(r, c); } + + ///--- ui methods + /** * This method scans and evaluates the user input. * -- 2.43.0 From 1000ef93cf1f04a698681cc3468ea669dbee5053 Mon Sep 17 00:00:00 2001 From: selim Date: Wed, 27 Dec 2023 19:31:14 +0100 Subject: [PATCH 28/31] Further descriptions. --- .../de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 7888480..c5b4094 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -14,7 +14,7 @@ import java.util.regex.Pattern; * A simplified spreadsheet class for the PR1 programming lab at Hochschule Mannheim. * One aspect worth mentioning is that it only supports long numbers, not doubles. * - * @author Oliver Hummel + * @author Selim Eser (2211482) */ public class Spreadsheet { Cell[][] cells; @@ -144,7 +144,8 @@ public class Spreadsheet { /** * This method does the actual evaluation/calcluation of a specific cell * - * @param row,col the name of row and column of the cell + * @param row The number of the cell row. + * @param col The number of the cell column. * @return Nothing. */ private void evaluateCell(int row, int col) { -- 2.43.0 From 324dfdd1ea91ab4f9aed7e553ddba2d759656d8b Mon Sep 17 00:00:00 2001 From: selim Date: Wed, 27 Dec 2023 19:52:33 +0100 Subject: [PATCH 29/31] Test folder created. --- .../informatik/spreadsheet/SpreadsheetTest.java | 10 ++++++++++ PR1-Spreadsheet.iml | 1 + 2 files changed, 11 insertions(+) create mode 100644 Axel/test/de/hs_mannheim/informatik/spreadsheet/SpreadsheetTest.java diff --git a/Axel/test/de/hs_mannheim/informatik/spreadsheet/SpreadsheetTest.java b/Axel/test/de/hs_mannheim/informatik/spreadsheet/SpreadsheetTest.java new file mode 100644 index 0000000..f6ac17e --- /dev/null +++ b/Axel/test/de/hs_mannheim/informatik/spreadsheet/SpreadsheetTest.java @@ -0,0 +1,10 @@ +package de.hs_mannheim.informatik.spreadsheet; + +import static org.junit.jupiter.api.Assertions.*; + +class SpreadsheetTest { + + @org.junit.jupiter.api.Test + void sum() { + } +} \ No newline at end of file diff --git a/PR1-Spreadsheet.iml b/PR1-Spreadsheet.iml index ea954f0..6319d91 100644 --- a/PR1-Spreadsheet.iml +++ b/PR1-Spreadsheet.iml @@ -4,6 +4,7 @@ + -- 2.43.0 From 33bdf1fabc63932370075b78e3803bb1c7792330 Mon Sep 17 00:00:00 2001 From: selim Date: Wed, 27 Dec 2023 21:48:29 +0100 Subject: [PATCH 30/31] ToString fixed. --- .../informatik/spreadsheet/Spreadsheet.java | 8 ++++---- PR1-Spreadsheet.iml | 16 ++++++++++++++++ 2 files 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 c5b4094..9166bfd 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -584,7 +584,7 @@ public class Spreadsheet { for (int i = 0; i < cells[0].length; i++) { sb.append("----------------------"); } - sb.append("------"); + sb.append("--------"); sb.append(System.lineSeparator()); sb.append(String.format(" " + "%2s", rc++) + " |"); @@ -600,7 +600,7 @@ public class Spreadsheet { for (int i = 0; i < cells[0].length; i++) { sb.append("----------------------"); } - sb.append("------"); + sb.append("--------"); sb.append(System.lineSeparator()); return sb.toString(); @@ -628,7 +628,7 @@ public class Spreadsheet { for (int i = 0; i < cells[0].length; i++) { sb.append("----------------------"); } - sb.append("------"); + sb.append("--------"); sb.append(System.lineSeparator()); sb.append(String.format(" " + "%2s", rc++) + " |"); @@ -641,7 +641,7 @@ public class Spreadsheet { for (int i = 0; i < cells[0].length; i++) { sb.append("----------------------"); } - sb.append("------"); + sb.append("--------"); sb.append(System.lineSeparator()); return sb.toString(); diff --git a/PR1-Spreadsheet.iml b/PR1-Spreadsheet.iml index 6319d91..9dd7111 100644 --- a/PR1-Spreadsheet.iml +++ b/PR1-Spreadsheet.iml @@ -8,5 +8,21 @@ + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.43.0 From 69c01f6bec21c25fb45725540a2b0be3a672962c Mon Sep 17 00:00:00 2001 From: selim Date: Thu, 28 Dec 2023 01:36:37 +0100 Subject: [PATCH 31/31] JUnit5 function tests done. --- Axel/resources/zahlen.csv | 19 +- .../informatik/spreadsheet/Axel.java | 2 +- .../informatik/spreadsheet/Cell.java | 2 +- .../informatik/spreadsheet/Spreadsheet.java | 2 +- .../spreadsheet/SpreadsheetTest.java | 192 +++++++++++++++++- 5 files changed, 203 insertions(+), 14 deletions(-) diff --git a/Axel/resources/zahlen.csv b/Axel/resources/zahlen.csv index 9167e5d..5bce6de 100644 --- a/Axel/resources/zahlen.csv +++ b/Axel/resources/zahlen.csv @@ -1,9 +1,10 @@ -=2,,,=SUMME(A1:A6),,,,,,,, -,,,,,,,,,,, -,,,,,,,,,,, -,,,,,,,,,,, -,,,,,,,,,,, -,,,,,,,,,,, -,,,,,,,,,,, -,,,,,,,,,,, -,,,,,,,,,,, +=MITTELWERT(B1:C10),=10,=234,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,, diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index f684c00..46d1b7d 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -7,7 +7,7 @@ import java.util.Scanner; /** * Part of a simplified spreadsheet system for the PR1 programming lab at Hochschule Mannheim. * - * @author Oliver Hummel + * @author Oliver Hummel, Selim Eser (2211482) */ public class Axel { diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java index f80e156..b02a610 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java @@ -4,7 +4,7 @@ package de.hs_mannheim.informatik.spreadsheet; * Part of a simplified spreadsheet system for the PR1 programming lab at Hochschule Mannheim. * A cell needs to be able to hold a formula and a value * - * @author Oliver Hummel + * @author Oliver Hummel, Selim Eser (2211482) */ public class Cell { private String formula = ""; diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 9166bfd..fcf8845 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -14,7 +14,7 @@ import java.util.regex.Pattern; * A simplified spreadsheet class for the PR1 programming lab at Hochschule Mannheim. * One aspect worth mentioning is that it only supports long numbers, not doubles. * - * @author Selim Eser (2211482) + * @author Oliver Hummel, Selim Eser (2211482) */ public class Spreadsheet { Cell[][] cells; diff --git a/Axel/test/de/hs_mannheim/informatik/spreadsheet/SpreadsheetTest.java b/Axel/test/de/hs_mannheim/informatik/spreadsheet/SpreadsheetTest.java index f6ac17e..8d73a4e 100644 --- a/Axel/test/de/hs_mannheim/informatik/spreadsheet/SpreadsheetTest.java +++ b/Axel/test/de/hs_mannheim/informatik/spreadsheet/SpreadsheetTest.java @@ -1,10 +1,198 @@ package de.hs_mannheim.informatik.spreadsheet; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import static org.junit.jupiter.api.Assertions.*; class SpreadsheetTest { - @org.junit.jupiter.api.Test - void sum() { + String[][] cells = {{"1","2"},{"2","4"},{"3","6"}}; + + @Test + void sumTest() { + + double result = 0; + + for(int r = 0; r0) + result *= Double.parseDouble(cells[r][c]); + else { + result = Double.parseDouble(cells[r][c]); + counter++; + } + assertEquals(288,result); + } + @Test + void averageTest() { + + double result = 0; + int counter = 0; + + for(int r = 0; r cellNames = new ArrayList<>(); + + double result = 0; + double avg = 0; + int counter = 0; + for(int r = 0; r copyCellNames = new ArrayList<>(cellNames); + double[] frequency = new double[cellNames.size()]; + Arrays.fill(frequency,1); + ArrayList relativeFrequency = new ArrayList<>(); + double mem = 0; + + for(int i = 0; i< cellNames.size(); i++) { + for(int t = 0; t cellNames = new ArrayList<>(); + + for(int r = 0; r< cells.length; r++) + for(int c = 0; c Double.parseDouble(cellNames.get(i))) + result = Double.parseDouble(cellNames.get(i)); + + assertEquals(1,result); + } + @Test + void maxTest() { + ArrayList cellNames = new ArrayList<>(); + + for(int r = 0; r< cells.length; r++) + for(int c = 0; c