diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index cd6e2f6..53ccd58 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -140,6 +140,27 @@ public class Spreadsheet { cells[row][col].setValue("" + result); } + /** + * Method for calculating the amount of cells with values inside 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 counted cells with values calculated. + */ + private long counterOfCellsWithValue(String startCellName, String endCellName){ + long counter = 0; + for(char col = startCellName.charAt(0); col <= endCellName.charAt(0); col++){ + + for(int row = Integer.parseInt(startCellName.substring(1)); row <= Integer.parseInt(endCellName.substring(1)); row++) { + String value = get((row - 1), (col - 'A')); + + if(!value.isEmpty()){ + counter++; + } + } + } + return counter; + } + /** * 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. @@ -199,25 +220,8 @@ public class Spreadsheet { * @return The arithmetic average calculated. */ private long mit(String startCellName, String endCellName) { - long result = 0; - int counter = 0; - for(char col = startCellName.charAt(0); col <= endCellName.charAt(0); col++){ - - for(int row = Integer.parseInt(startCellName.substring(1)); row <= Integer.parseInt(endCellName.substring(1)); row++) { - String value = get((row - 1), (col - 'A')); - - if(!value.isEmpty()){ - result += Long.parseLong(value); - }else{ - continue; - } - - counter++; - } - } - result /= counter; - return result; + return sum(startCellName, endCellName)/ counterOfCellsWithValue(startCellName, endCellName); } /**