forked from hummel/PR1-Spreadsheet
Kleines Menü erstellt
Zeilen und Spaltenbegrenzung csvReader erstellt Summenformel und Produktformel erstellt. + Die Möglichkeit erstellt vorhandene Textdatei zu verändern und diese zu Speichern. Wird beim auslesen auch verändert ausgegeben. Mittelwert Min und Max Methoden hinzugefügtmain
parent
98942ba56d
commit
091418cbde
|
@ -153,18 +153,18 @@ public class Spreadsheet {
|
|||
String formula = cells[row][col].getFormula();
|
||||
String result = "";
|
||||
|
||||
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)); // TODO adapt to cells with two digits
|
||||
else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9)
|
||||
result = "" + multiplier(formula.substring(6, 8), formula.substring(9, 11)); // TODO
|
||||
result = "" + multiplier(formula.substring(8, 10), formula.substring(11, 13)); // TODO
|
||||
else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5)
|
||||
result = "TODO"; // TODO
|
||||
result = "" + mittelwert(formula.substring(11, 13), formula.substring(14, 16)); // TODO
|
||||
else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung
|
||||
result = "TODO"; // TODO
|
||||
else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert
|
||||
result = "TODO"; // TODO
|
||||
result = "" + min(formula.substring(4, 6), formula.substring(7, 9)); // TODO
|
||||
else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung
|
||||
result = "TODO"; // TODO
|
||||
result = "" + max(formula.substring(4, 6), formula.substring(7, 9)); // TODO
|
||||
else if (!formula.isEmpty()) {
|
||||
try {
|
||||
result = "" + calculate(formula);
|
||||
|
@ -175,7 +175,7 @@ public class Spreadsheet {
|
|||
|
||||
cells[row][col].setValue("" + result);
|
||||
}
|
||||
|
||||
//substring start und ende auf die entsprechende Wortlänge bei der Bedingung anpassen
|
||||
/**
|
||||
* Method for calculating the sum 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.
|
||||
|
@ -216,6 +216,65 @@ public class Spreadsheet {
|
|||
|
||||
return result;
|
||||
}
|
||||
private long mittelwert(String startCellName, String endCellName) {
|
||||
|
||||
int startRow = getRow(startCellName);
|
||||
int startCol = getCol(startCellName);
|
||||
int endRow = getRow(endCellName);
|
||||
int endCol = getCol(endCellName);
|
||||
int counter = 0;
|
||||
long summe = 0;
|
||||
|
||||
long result = 0;
|
||||
|
||||
for (int i = startRow; i <= endRow; i++) {
|
||||
for (int j = startCol; j <= endCol; j++) {
|
||||
counter++;
|
||||
summe += (Integer.parseInt(cells[i][j].getValue()));
|
||||
}
|
||||
}
|
||||
result = summe / counter;
|
||||
|
||||
return result;
|
||||
}
|
||||
private long min(String startCellName, String endCellName) {
|
||||
int startRow = getRow(startCellName);
|
||||
int startCol = getCol(startCellName);
|
||||
int endRow = getRow(endCellName);
|
||||
int endCol = getCol(endCellName);
|
||||
long result = 0;
|
||||
|
||||
for (int i = startRow; i <= endRow; i++) {
|
||||
for (int j = startCol; j <= endCol; j++) {
|
||||
|
||||
result = (Integer.parseInt(cells[i][j].getValue()));
|
||||
if(result > (Integer.parseInt(cells[i][j].getValue()))) {
|
||||
result = (Integer.parseInt(cells[i][j].getValue()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private long max(String startCellName, String endCellName) {
|
||||
int startRow = getRow(startCellName);
|
||||
int startCol = getCol(startCellName);
|
||||
int endRow = getRow(endCellName);
|
||||
int endCol = getCol(endCellName);
|
||||
long result = 0;
|
||||
|
||||
for (int i = startRow; i <= endRow; i++) {
|
||||
for (int j = startCol; j <= endCol; j++) {
|
||||
|
||||
if(result < (Integer.parseInt(cells[i][j].getValue()))) {
|
||||
result = (Integer.parseInt(cells[i][j].getValue()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// TODO implement
|
||||
|
|
Loading…
Reference in New Issue