1
0
Fork 0

mehr als einstellig Zellen befüllen geht jetzt

(2 kleine Bug fixxes, wenn die länge vom Spreadsheet nicht 1:1 ist)
main
Florian Hörner 2024-01-03 15:40:33 +01:00
parent ef2ad7511e
commit c23bcf7113
1 changed files with 24 additions and 4 deletions

View File

@ -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) + " | ");
}