product of a cell block
parent
859be3633e
commit
e8114209f2
|
@ -11,10 +11,14 @@ import java.util.Scanner;
|
|||
public class Axel {
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
Spreadsheet spr = new Spreadsheet(20,10);
|
||||
String cell, in;
|
||||
int rows, cols;
|
||||
Scanner kb = new Scanner(System.in);
|
||||
|
||||
System.out.print("Rows:");
|
||||
rows=Integer.parseInt(kb.nextLine());
|
||||
System.out.print("Cols:");
|
||||
cols=Integer.parseInt(kb.nextLine());
|
||||
Spreadsheet spr=new Spreadsheet(rows,cols);
|
||||
//spr.put("A3", "3");
|
||||
//spr.put("A2", "1");
|
||||
|
||||
|
|
|
@ -130,9 +130,13 @@ public class Spreadsheet {
|
|||
result = "" + sum(formula.substring(6, 8), formula.substring(9, 12));
|
||||
else
|
||||
result = "" + sum(formula.substring(6, 8), formula.substring(9, 11));
|
||||
|
||||
else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9)
|
||||
result = "TODO"; // TODO
|
||||
if(formula.length()==16)
|
||||
result = "" + product(formula.substring(8, 11), formula.substring(12, 15));
|
||||
else if(formula.length()==15)
|
||||
result = "" + product(formula.substring(8, 10), formula.substring(11, 14));
|
||||
else
|
||||
result = "" + product(formula.substring(8, 10), formula.substring(11, 13));
|
||||
else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5)
|
||||
result = "TODO"; // TODO
|
||||
else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung
|
||||
|
@ -180,6 +184,28 @@ public class Spreadsheet {
|
|||
}
|
||||
return sum;
|
||||
}
|
||||
private long product(String startCellName, String endCellName) {
|
||||
int product=1;
|
||||
int startCellRow;
|
||||
int endCellRow;
|
||||
if(startCellName.length()==3)
|
||||
startCellRow=Integer.parseInt((startCellName.charAt(1)+"")+(startCellName.charAt(2)+""))-1;
|
||||
else
|
||||
startCellRow=startCellName.charAt(1)-'1';
|
||||
if(endCellName.length()==3)
|
||||
endCellRow=Integer.parseInt((endCellName.charAt(1)+"")+(endCellName.charAt(2)+""))-1;
|
||||
else
|
||||
endCellRow=endCellName.charAt(1)-'1';
|
||||
for(int i=startCellName.charAt(0)-'A'; i<=endCellName.charAt(0)-'A'; i++) {
|
||||
for(int j=startCellRow; j<=endCellRow; j++) {
|
||||
if(cells[j][i].isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
product=product*Integer.parseInt(cells[j][i].getValue());
|
||||
}
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calculates the result of a "normal" algebraic expression. It only needs to support
|
||||
|
|
Loading…
Reference in New Issue