From 9096432995e060ffa5b765fb8f319135a88d727e Mon Sep 17 00:00:00 2001 From: ERANZER Date: Fri, 5 Jan 2024 20:18:26 +0100 Subject: [PATCH] min value of a cell block --- .../informatik/spreadsheet/Spreadsheet.java | 21 +++++++++++++++++-- 1 file changed, 19 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 553edaf..c077ec1 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -155,8 +155,13 @@ public class Spreadsheet { result = "" + max(formula.substring(4, 6), formula.substring(7, 10)); else result = "" + max(formula.substring(4, 6), formula.substring(7, 9)); - else if (formula.startsWith("MIN(")) // e.g. MAX(A1:A10) -> Standardabweichung - result = "TODO"; // TODO + else if (formula.startsWith("MIN(")) + if(formula.length()==12) + result = "" + min(formula.substring(4, 7), formula.substring(8, 11)); + else if(formula.length()==11) + result = "" + min(formula.substring(4, 6), formula.substring(7, 10)); + else + result = "" + min(formula.substring(4, 6), formula.substring(7, 9)); else if (!formula.isEmpty()) { try { result = "" + calculate(formula); @@ -229,6 +234,18 @@ public class Spreadsheet { } return max; } + private int min(String startCellName,String endCellName) { + int min=Integer.MAX_VALUE; + for(int i=startCellName.charAt(0)-'A'; i<=endCellName.charAt(0)-'A'; i++) { + for(int j=Integer.parseInt(startCellName.substring(1))-1; j<=Integer.parseInt(endCellName.substring(1))-1; j++) { + if(cells[j][i].isEmpty()) + continue; + else if(min>Integer.parseInt(cells[j][i].getValue())) + min=Integer.parseInt(cells[j][i].getValue()); + } + } + return min; + } /** * This method calculates the result of a "normal" algebraic expression. It only needs to support