From 9c5b38d9db311cca9900b493b7bc9b323dda9599 Mon Sep 17 00:00:00 2001 From: ERANZER Date: Fri, 5 Jan 2024 11:58:29 +0100 Subject: [PATCH] sum of a cell block --- .../de/hs_mannheim/informatik/spreadsheet/Axel.java | 10 +++++----- .../informatik/spreadsheet/Spreadsheet.java | 13 ++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index 3ce5e51..ce1f56e 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -15,12 +15,12 @@ public class Axel { String cell, in; Scanner kb = new Scanner(System.in); - spr.put("A3", "3"); - spr.put("A2", "1"); + //spr.put("A3", "3"); + //spr.put("A2", "1"); - spr.put("B9", "=41+A2"); - spr.put("J5", "=7*6"); - spr.put("J6", "=3/2"); + //spr.put("B9", "=41+A2"); + //spr.put("J5", "=7*6"); + //spr.put("J6", "=3/2"); while(true) { 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 4333146..f83c5f5 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -150,9 +150,16 @@ public class Spreadsheet { * @return The sum calculated. */ private long sum(String startCellName, String endCellName) { - // TODO implement - - return 0; + int sum=0; + for(int i=startCellName.charAt(0)-'A'; i<=endCellName.charAt(0)-'A'; i++) { + for(int j=startCellName.charAt(1)-'1'; j<=endCellName.charAt(1)-'1'; j++) { + if(cells[i][j].isEmpty()) { + continue; + } + sum+=Integer.parseInt(cells[j][i].getValue()); + } + } + return sum; } /**