forked from hummel/PR1-Spreadsheet
prod() Methode ergänzt
parent
bbbaf7473a
commit
bbe478ff81
|
@ -120,7 +120,7 @@ public class Spreadsheet {
|
||||||
if (formula.startsWith("SUMME(")) // e.g. SUMME(A3:A8)
|
if (formula.startsWith("SUMME(")) // e.g. SUMME(A3:A8)
|
||||||
result = "" + sum(formula.substring(6, colon), endSubstring);
|
result = "" + sum(formula.substring(6, colon), endSubstring);
|
||||||
else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9)
|
else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9)
|
||||||
result = "" + prod(formula.substring(9, colon), endSubstring);
|
result = "" + prod(formula.substring(8, colon), endSubstring);
|
||||||
else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5)
|
else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5)
|
||||||
result = "" + mit(formula.substring(12, colon), endSubstring);
|
result = "" + mit(formula.substring(12, colon), endSubstring);
|
||||||
else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung
|
else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung
|
||||||
|
@ -153,8 +153,7 @@ public class Spreadsheet {
|
||||||
|
|
||||||
for(int row = Integer.parseInt(startCellName.substring(1)); row <= Integer.parseInt(endCellName.substring(1)); row++) {
|
for(int row = Integer.parseInt(startCellName.substring(1)); row <= Integer.parseInt(endCellName.substring(1)); row++) {
|
||||||
|
|
||||||
String value = get((row - 1), (col - 'A'));
|
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
|
||||||
System.out.println(value);
|
|
||||||
|
|
||||||
if(!value.isEmpty()){
|
if(!value.isEmpty()){
|
||||||
result += Long.parseLong(value);
|
result += Long.parseLong(value);
|
||||||
|
@ -171,9 +170,26 @@ public class Spreadsheet {
|
||||||
* @return The product calculated.
|
* @return The product calculated.
|
||||||
*/
|
*/
|
||||||
private long prod(String startCellName, String endCellName) {
|
private long prod(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'));
|
||||||
|
System.out.println(value);
|
||||||
|
|
||||||
|
if(result == 0){
|
||||||
|
result = Long.parseLong(value);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(!value.isEmpty() && !(value.equals("0"))){
|
||||||
|
result *= Long.parseLong(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue