Spreadsheet standardDeviation start of implementation.
parent
e9a9ac5527
commit
c059a4289a
|
@ -54,6 +54,10 @@ public class Spreadsheet {
|
||||||
return get(getRow(cellName), getCol(cellName));
|
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) {
|
private void put(int row, int col, String value) {
|
||||||
if (!value.startsWith("="))
|
if (!value.startsWith("="))
|
||||||
cells[row][col].setValue(value);
|
cells[row][col].setValue(value);
|
||||||
|
@ -248,6 +252,21 @@ public class Spreadsheet {
|
||||||
result /= counter;
|
result /= counter;
|
||||||
return result;
|
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
|
* This method calculates the result of a "normal" algebraic expression. It only needs to support
|
||||||
|
|
Loading…
Reference in New Issue