forked from hummel/PR1-Spreadsheet
counterOfCellsWithValue() Methode ergänzt. Angepasste mit() Methode
parent
111b4a36eb
commit
a0117ae961
|
@ -140,6 +140,27 @@ public class Spreadsheet {
|
||||||
cells[row][col].setValue("" + result);
|
cells[row][col].setValue("" + result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for calculating the amount of cells with values inside a rectangular block of cells, such as from A1 to B3.
|
||||||
|
* @param startCellName The name of the cell in the upper left corner of the rectangle.
|
||||||
|
* @param endCellName The name of the cell in the lower right corner of the rectangle.
|
||||||
|
* @return The counted cells with values calculated.
|
||||||
|
*/
|
||||||
|
private long counterOfCellsWithValue(String startCellName, String endCellName){
|
||||||
|
long counter = 0;
|
||||||
|
for(char col = startCellName.charAt(0); col <= endCellName.charAt(0); col++){
|
||||||
|
|
||||||
|
for(int row = Integer.parseInt(startCellName.substring(1)); row <= Integer.parseInt(endCellName.substring(1)); row++) {
|
||||||
|
String value = get((row - 1), (col - 'A'));
|
||||||
|
|
||||||
|
if(!value.isEmpty()){
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method for calculating the sum of a rectangular block of cells, such as from A1 to B3.
|
* Method for calculating the sum of a rectangular block of cells, such as from A1 to B3.
|
||||||
* @param startCellName The name of the cell in the upper left corner of the rectangle.
|
* @param startCellName The name of the cell in the upper left corner of the rectangle.
|
||||||
|
@ -199,25 +220,8 @@ public class Spreadsheet {
|
||||||
* @return The arithmetic average calculated.
|
* @return The arithmetic average calculated.
|
||||||
*/
|
*/
|
||||||
private long mit(String startCellName, String endCellName) {
|
private long mit(String startCellName, String endCellName) {
|
||||||
long result = 0;
|
|
||||||
int counter = 0;
|
|
||||||
|
|
||||||
for(char col = startCellName.charAt(0); col <= endCellName.charAt(0); col++){
|
return sum(startCellName, endCellName)/ counterOfCellsWithValue(startCellName, endCellName);
|
||||||
|
|
||||||
for(int row = Integer.parseInt(startCellName.substring(1)); row <= Integer.parseInt(endCellName.substring(1)); row++) {
|
|
||||||
String value = get((row - 1), (col - 'A'));
|
|
||||||
|
|
||||||
if(!value.isEmpty()){
|
|
||||||
result += Long.parseLong(value);
|
|
||||||
}else{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result /= counter;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue