From 111b4a36ebb22a3d42bd44df236513fe47952e51 Mon Sep 17 00:00:00 2001 From: 3011357 <3011357@stud.hs-mannheim.de> Date: Sat, 6 Jan 2024 20:36:37 +0100 Subject: [PATCH] =?UTF-8?q?min()=20und=20max()=20Methode=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../informatik/spreadsheet/Spreadsheet.java | 34 +++++++++++++++++-- 1 file changed, 32 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 18dcd7a..cd6e2f6 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -239,9 +239,24 @@ public class Spreadsheet { * @return The minimum value of the block. */ private long min(String startCellName, String endCellName) { + long result = 0; + for(char col = startCellName.charAt(0); col <= endCellName.charAt(0); col++){ - return 0; + for(int row = Integer.parseInt(startCellName.substring(1)); row <= Integer.parseInt(endCellName.substring(1)); row++) { + + String value = get((row - 1), (col - 'A')); //"-1" because we start with 1 instead of 0. "-A" because A in ascii is 65, but we start with 0 + + if((col == startCellName.charAt(0)) && (row == Integer.parseInt(startCellName.substring(1)))) { + result = Long.parseLong(value); + } + else if(!value.isEmpty() && (Long.parseLong(value) < result)){ + result = Long.parseLong(value); + } + } + } + + return result; } /** @@ -251,9 +266,24 @@ public class Spreadsheet { * @return The maximum value of the block. */ private long max(String startCellName, String endCellName) { + long result = 0; + for(char col = startCellName.charAt(0); col <= endCellName.charAt(0); col++){ - return 0; + for(int row = Integer.parseInt(startCellName.substring(1)); row <= Integer.parseInt(endCellName.substring(1)); row++) { + + String value = get((row - 1), (col - 'A')); //"-1" because we start with 1 instead of 0. "-A" because A in ascii is 65, but we start with 0 + + if((col == startCellName.charAt(0)) && (row == Integer.parseInt(startCellName.substring(1)))) { + result = Long.parseLong(value); + } + else if(!value.isEmpty() && (Long.parseLong(value) > result)){ + result = Long.parseLong(value); + } + } + } + + return result; }