forked from hummel/PR1-Spreadsheet
Prod u. 10. Reihe wirklich benutzbar
parent
203a833bc6
commit
aba1d8bf54
|
@ -41,7 +41,6 @@ public class Axel {
|
||||||
form+=command.charAt(i);
|
form+=command.charAt(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spr.put(cell, form);
|
spr.put(cell, form);
|
||||||
|
|
||||||
}while(true);
|
}while(true);
|
||||||
|
|
|
@ -74,10 +74,9 @@ public class Spreadsheet {
|
||||||
return cellName.charAt(1) - '1';
|
return cellName.charAt(1) - '1';
|
||||||
}else {
|
}else {
|
||||||
int Row = 0;
|
int Row = 0;
|
||||||
Row +=((cellName.charAt(1)-48)*10);
|
Row +=((cellName.charAt(1)-'0')*10);
|
||||||
Row +=(cellName.charAt(2)-49);
|
Row +=(cellName.charAt(2)-'0');
|
||||||
System.out.println(Row);
|
return Row-1;
|
||||||
return Row;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// -----
|
// -----
|
||||||
|
@ -128,11 +127,23 @@ public class Spreadsheet {
|
||||||
private void evaluateCell(int row, int col) {
|
private void evaluateCell(int row, int col) {
|
||||||
String formula = cells[row][col].getFormula();
|
String formula = cells[row][col].getFormula();
|
||||||
String result = "";
|
String result = "";
|
||||||
|
int offset = 0;
|
||||||
|
int offsetEnd = 0;
|
||||||
|
int diff=0;
|
||||||
|
for(int i = 0; i<formula.length();i++) {
|
||||||
|
if(formula.charAt(i)=='(') {
|
||||||
|
offset=i+1;
|
||||||
|
}else if(formula.charAt(i)==')') {
|
||||||
|
offsetEnd=i;
|
||||||
|
}
|
||||||
|
else if(formula.charAt(i)==':') {
|
||||||
|
diff=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (formula.startsWith("SUMME(")) { // e.g. SUMME(A3:A8)
|
if (formula.startsWith("SUMME(")) { // e.g. SUMME(A3:A8)
|
||||||
result += sum(formula.substring(6, 8), formula.substring(9, 11));
|
result += sum(formula.substring(offset, diff), formula.substring(diff+1,offsetEnd));
|
||||||
}else if (formula.startsWith("PRODUKT(")) { // e.g. PRODUKT(A3:B9)
|
}else if (formula.startsWith("PRODUKT(")) { // e.g. PRODUKT(A3:B9)
|
||||||
result = "TODO"; // TODO
|
result += prod(formula.substring(offset, diff), formula.substring(diff+1, offsetEnd));; // TODO
|
||||||
}else if (formula.startsWith("MITTELWERT(")) { // e.g. MITTELWERT(A3:A5)
|
}else if (formula.startsWith("MITTELWERT(")) { // e.g. MITTELWERT(A3:A5)
|
||||||
result = "TODO"; // TODO
|
result = "TODO"; // TODO
|
||||||
}else if (formula.startsWith("STABW(")) { // e.g. STABW(C6:D8) -> Standardabweichung
|
}else if (formula.startsWith("STABW(")) { // e.g. STABW(C6:D8) -> Standardabweichung
|
||||||
|
@ -162,12 +173,35 @@ public class Spreadsheet {
|
||||||
long res = 0;
|
long res = 0;
|
||||||
for(int j = getRow(startCellName); j< (getRow(endCellName)+1);j++){
|
for(int j = getRow(startCellName); j< (getRow(endCellName)+1);j++){
|
||||||
for(int i = getCol(startCellName); i< (getCol(endCellName)+1);i++) {
|
for(int i = getCol(startCellName); i< (getCol(endCellName)+1);i++) {
|
||||||
if(!cells[j][i].getValue().isBlank())
|
if(!cells[j][i].getValue().isBlank()) {
|
||||||
res += Long.parseLong(cells[j][i].getValue());
|
res += Long.parseLong(cells[j][i].getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Method for calculating the product 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 endCellName The name of the cell in the lower right corner of the rectangle.
|
||||||
|
* @return The product calculated.
|
||||||
|
*/
|
||||||
|
private long prod(String startCellName, String endCellName) {
|
||||||
|
long res = 1;
|
||||||
|
boolean anyNumbers= false;
|
||||||
|
for(int j = getRow(startCellName); j< (getRow(endCellName)+1);j++){
|
||||||
|
for(int i = getCol(startCellName); i< (getCol(endCellName)+1);i++) {
|
||||||
|
if(!cells[j][i].getValue().isBlank()) {
|
||||||
|
res*= Long.parseLong(cells[j][i].getValue());
|
||||||
|
anyNumbers = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(anyNumbers)
|
||||||
|
return res;
|
||||||
|
else
|
||||||
|
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
|
||||||
|
@ -197,7 +231,6 @@ public class Spreadsheet {
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 2; i<args.size();) {
|
for(int i = 2; i<args.size();) {
|
||||||
System.out.println(args.get(i));
|
|
||||||
String val = "";
|
String val = "";
|
||||||
switch(args.get(i-1)) {
|
switch(args.get(i-1)) {
|
||||||
case "+":
|
case "+":
|
||||||
|
|
Loading…
Reference in New Issue