1
0
Fork 0

Spreadsheet standardDeviation start of implementation.

pull/1/head
selim 2023-12-26 05:40:50 +01:00
parent e9a9ac5527
commit c059a4289a
1 changed files with 19 additions and 0 deletions

View File

@ -54,6 +54,10 @@ public class Spreadsheet {
return get(getRow(cellName), getCol(cellName));
}
public String getCellName(int row, int col) {
return "" + ((char) ('A' + col)) + (row+1);
}
private void put(int row, int col, String value) {
if (!value.startsWith("="))
cells[row][col].setValue(value);
@ -248,6 +252,21 @@ public class Spreadsheet {
result /= counter;
return result;
}
private double standardDeviation(String startCellName, String endCellName){
ArrayList<String> cellNames = new ArrayList<>();
long avg = 0;
int counter = 0;
for(int r = getRow(startCellName); r<getRow(endCellName)+1; r++)
for(int c = getCol(startCellName); c<getCol(endCellName)+1; c++)
try {
avg += Long.parseLong(cells[r][c].getValue());
counter ++;
cellNames.add(getCellName(r, c));
} catch (NumberFormatException n){}
avg /= counter;
return 0;
}
/**
* This method calculates the result of a "normal" algebraic expression. It only needs to support