From c23bcf71139ddbb1ad84d2859e13695e90406bcc Mon Sep 17 00:00:00 2001 From: 3012330 <3012330@stud.hs-mannheim.de> Date: Wed, 3 Jan 2024 15:40:33 +0100 Subject: [PATCH] =?UTF-8?q?mehr=20als=20einstellig=20Zellen=20bef=C3=BClle?= =?UTF-8?q?n=20geht=20jetzt=20(2=20kleine=20Bug=20fixxes,=20wenn=20die=20l?= =?UTF-8?q?=C3=A4nge=20vom=20Spreadsheet=20nicht=201:1=20ist)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../informatik/spreadsheet/Spreadsheet.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 312e2bd..f63556a 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -69,9 +69,29 @@ public class Spreadsheet { put(getRow(cellName), getCol(cellName), value); } - private int getCol(String cellName) {return cellName.charAt(0) - 'A';} - private int getRow(String cellName) {return cellName.charAt(1) - '1';} + private int getCol(String cellName) { + int merker = 0; + for (int i = 0; i < cellName.length(); i++) { + if (cellName.charAt(i) >= 'A' && cellName.charAt(i) <= 'Z') { + merker = (merker * 10) + (cellName.charAt(i) - ('A'-1)); + } else { + break; + } + } + return merker-1; + } + + + private int getRow(String cellName) { + int merker = 0; + for (int i = 0; i < cellName.length(); i++) { + if (!(cellName.charAt(i) >= 'A' && cellName.charAt(i) <= 'Z')) { + merker = (merker * 10) + (cellName.charAt(i) - '0'); + } + } + return merker-1; + } // ----- // business logic @@ -104,7 +124,7 @@ public class Spreadsheet { else out.print(cell.getValue()); - if (cell != row[cells.length-1]) + if (cell != row[cells[0].length-1]) // "[0]" -> nimmt sonst die falsche Länge! out.print(","); } out.println(); @@ -190,7 +210,7 @@ public class Spreadsheet { StringBuilder sb = new StringBuilder(); sb.append(" "); - for (int i = 0; i < cells.length; i++) { + for (int i = 0; i < cells[0].length; i++) { // "[0]" -> nimmt sonst die falsche Länge! sb.append(" " + (char)('A'+ i) + " | "); }