1
0
Fork 0

Javadoc-kommentare vervollständigt

master
devra 2024-01-08 22:48:15 +01:00
parent c7af9a2a5e
commit e5ada63b88
2 changed files with 44 additions and 25 deletions

View File

@ -1,4 +1,4 @@
=SUMME(C1:E2),,=1,=2,=3,,,,, =SUMME(C1:E2),=MAX(E2:C1),=1,=2,=3,,,,,
,,=4,=5,=6,,,,, ,,=4,=5,=6,,,,,
,,,,=0,,,,, ,,,,=0,,,,,
,,,,=0,,,,, ,,,,=0,,,,,

1 =SUMME(C1:E2) =MAX(E2:C1) =1 =2 =3
2 =4 =5 =6
3 =0
4 =0

View File

@ -153,7 +153,6 @@ public class Spreadsheet {
result = "" + sum(onlyCells[0], onlyCells[1]); result = "" + sum(onlyCells[0], onlyCells[1]);
} }
} }
else if (formula.startsWith("PRODUKT(")) {// e.g. PRODUKT(A3:B9) else if (formula.startsWith("PRODUKT(")) {// e.g. PRODUKT(A3:B9)
String[] onlyCells = formula.substring(8, formula.length() - 1).split(":"); String[] onlyCells = formula.substring(8, formula.length() - 1).split(":");
@ -161,9 +160,6 @@ public class Spreadsheet {
result = "" + pro(onlyCells[0], onlyCells[1]); result = "" + pro(onlyCells[0], onlyCells[1]);
} }
} }
else if (formula.startsWith("MITTEL(")) { // e.g. MITTEL(A3:A5) else if (formula.startsWith("MITTEL(")) { // e.g. MITTEL(A3:A5)
String[] onlyCells = formula.substring(7, formula.length() - 1).split(":"); String[] onlyCells = formula.substring(7, formula.length() - 1).split(":");
@ -171,9 +167,6 @@ public class Spreadsheet {
result = "" + mit(onlyCells[0], onlyCells[1]); result = "" + mit(onlyCells[0], onlyCells[1]);
} }
} }
else if (formula.startsWith("STABW(")) { // e.g. STABW(C6:D8) -> minimal-wert else if (formula.startsWith("STABW(")) { // e.g. STABW(C6:D8) -> minimal-wert
String[] onlyCells = formula.substring(6, formula.length() - 1).split(":"); String[] onlyCells = formula.substring(6, formula.length() - 1).split(":");
@ -182,25 +175,18 @@ public class Spreadsheet {
} }
} }
else if (formula.startsWith("MIN(")) { else if (formula.startsWith("MIN(")) {
String[] onlyCells = formula.substring(4, formula.length() - 1).split(":"); String[] onlyCells = formula.substring(4, formula.length() - 1).split(":");
if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) { if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) {
result = "" + min(onlyCells[0], onlyCells[1]); result = "" + min(onlyCells[0], onlyCells[1]);
} }
} }
else if (formula.startsWith("MAX(")) {// e.g. MAX(A1:A10) -> maximal-wert else if (formula.startsWith("MAX(")) {// e.g. MAX(A1:A10) -> maximal-wert
String[] onlyCells = formula.substring(4, formula.length() - 1).split(":"); String[] onlyCells = formula.substring(4, formula.length() - 1).split(":");
if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) { if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) {
result = "" + max(onlyCells[0], onlyCells[1]); result = "" + max(onlyCells[0], onlyCells[1]);
} }
} }
else if (!formula.isEmpty()) { else if (!formula.isEmpty()) {
try { try {
result = "" + calculate(formula); //calculates the result of a "normal" algebraic expression. result = "" + calculate(formula); //calculates the result of a "normal" algebraic expression.
@ -236,7 +222,12 @@ public class Spreadsheet {
return summe; return summe;
} }
// TODO: Javadoc comments /**
* 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 pro(String startCellName, String endCellName) { private long pro(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName); int werte[]=getValues(startCellName,endCellName);
@ -247,7 +238,12 @@ public class Spreadsheet {
return produkt; return produkt;
} }
// TODO: Javadoc comments /**
* Method for calculating the 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 average calculated.
*/
private long mit(String startCellName, String endCellName) { private long mit(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName); int werte[]=getValues(startCellName,endCellName);
@ -256,10 +252,14 @@ public class Spreadsheet {
summe+=werte[i]; summe+=werte[i];
} }
return summe/werte.length; return summe/werte.length;
} }
// TODO: Javadoc comments /**
* 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 double statbw(String startCellName, String endCellName) { private double statbw(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName); int werte[]=getValues(startCellName,endCellName);
@ -286,7 +286,12 @@ public class Spreadsheet {
/**
* Method for calculating the minimum-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 calculated.
*/
private long min(String startCellName, String endCellName) { private long min(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName); int werte[]=getValues(startCellName,endCellName);
@ -305,7 +310,12 @@ public class Spreadsheet {
} }
/**
* Method for calculating 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 calculated.
*/
private long max(String startCellName, String endCellName) { private long max(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName); int werte[]=getValues(startCellName,endCellName);
@ -324,7 +334,13 @@ public class Spreadsheet {
} }
// TODO: Javadoc comments /**
* Method for reading and saving the values 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 values that are read, saved in an int array.
*/
private int[] getValues(String startCellName, String endCellName) { private int[] getValues(String startCellName, String endCellName) {
int startZeile=getRow(startCellName); int startZeile=getRow(startCellName);
int startSpalte=getCol(startCellName); int startSpalte=getCol(startCellName);
@ -349,10 +365,9 @@ public class Spreadsheet {
} }
} }
} }
return werte; return werte;
} }
/** /**
* 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,
@ -440,7 +455,11 @@ public class Spreadsheet {
} }
//TODO: Javadoc Comment!! /**
* Method for checking if a given cell exists inside the current spreadsheet
* @param cellName The name of the cell that is suppsoed to be checked.
* @return true if cell exists inside spreadsheet.
*/
public boolean checkIfCellExists(String cellName) { public boolean checkIfCellExists(String cellName) {
if((getRow(cellName)+1)<=cells.length&&(getCol(cellName)+1)<=cells[0].length) { if((getRow(cellName)+1)<=cells.length&&(getCol(cellName)+1)<=cells[0].length) {
return true; return true;