1
0
Fork 0

min() und max() Methode ergänzt

main
Anastasia Kisner 2024-01-06 20:36:37 +01:00
parent 10f0aef19a
commit 111b4a36eb
1 changed files with 32 additions and 2 deletions

View File

@ -239,9 +239,24 @@ public class Spreadsheet {
* @return The minimum value of the block. * @return The minimum value of the block.
*/ */
private long min(String startCellName, String endCellName) { 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. * @return The maximum value of the block.
*/ */
private long max(String startCellName, String endCellName) { 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;
} }