1
0
Fork 0

Methoden zu den Formeln deklariert. In evaluateCell() Cell references für two-digits ermöglicht

main
Anastasia Kisner 2024-01-06 15:30:59 +01:00
parent d3326a5c3b
commit 44e9e9bc9c
2 changed files with 88 additions and 9 deletions

View File

@ -117,19 +117,21 @@ 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 colon = formula.indexOf(':');
String endSubstring = formula.substring((colon + 1), (formula.length()-1));
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 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 = "TODO"; // TODO result = "" + prod(formula.substring(9, colon), endSubstring);
else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5) else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5)
result = "TODO"; // TODO 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
result = "TODO"; // TODO result = "" + stabw(formula.substring(7, colon), endSubstring);
else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> kleinster Wert
result = "TODO"; // TODO result = "" + min(formula.substring(5, colon), endSubstring);
else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> größter Wert
result = "TODO"; // TODO result = "" + max(formula.substring(5, colon), endSubstring);
else if (!formula.isEmpty()) { else if (!formula.isEmpty()) {
try { try {
result = "" + calculate(formula); result = "" + calculate(formula);
@ -148,11 +150,71 @@ public class Spreadsheet {
* @return The sum calculated. * @return The sum calculated.
*/ */
private long sum(String startCellName, String endCellName) { private long sum(String startCellName, String endCellName) {
// TODO implement
return 0; return 0;
} }
/**
* 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) {
return 0;
}
/**
* Method for calculating the arithmetic average 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 arithmetic average calculated.
*/
private long mit(String startCellName, String endCellName) {
return 0;
}
/**
* Method for calculating the standard deviation 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 standard deviation calculated.
*/
private long stabw(String startCellName, String endCellName) {
return 0;
}
/**
* Method for finding the maximum value 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 minimum value of the block.
*/
private long min(String startCellName, String endCellName) {
return 0;
}
/**
* Method for finding the maximum value 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 maximum value of the block.
*/
private long max(String startCellName, String endCellName) {
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
* expressions like =B4 or =2+A3-B2, i.e. only with int numbers and other cells and with plus, * expressions like =B4 or =2+A3-B2, i.e. only with int numbers and other cells and with plus,

View File

@ -4,8 +4,25 @@
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/Axel/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/Axel/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Test" isTestSource="true" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component> </component>
</module> </module>