From ac408c1f23d0bba62e83effa7f00f85d2b302350 Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 19:13:33 +0100 Subject: [PATCH] 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