diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..420da78
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..bcc94e8
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ PR1-Spreadsheet
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java
index e38ea7e..dd9633f 100644
--- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java
+++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java
@@ -2,6 +2,8 @@ package de.hs_mannheim.informatik.spreadsheet;
//m
import java.io.FileNotFoundException;
+import java.util.Scanner;
+
/**
* Part of a simplified spreadsheet system for the PR1 programming lab at Hochschule Mannheim.
*
@@ -11,6 +13,13 @@ public class Axel {
public static void main(String[] args) throws FileNotFoundException {
Spreadsheet spr = new Spreadsheet(10,10);
+ Scanner sc= new Scanner(System.in);
+
+
+ boolean exit=false;
+ String readInput;
+ String currentCell;
+ String formula;
spr.put("A3", "123");
spr.put("A2", "1");
@@ -19,11 +28,54 @@ public class Axel {
spr.put("J5", "=7*6");
spr.put("J6", "=3/2");
+ //add some values for testing
+ spr.put("B1", "10");
+ spr.put("B2", "5");
+ spr.put("B3", "8");
+
+
+//
+
System.out.println(spr);
spr.saveCsv("/tmp/test.csv");
// TODO: You might want to put "UI loop" for entering value and formulas here resp. in some UI methods.
- }
+
+ do {
+
+ //set values in cells
+
+ System.out.println("cell:");
+ readInput= sc.nextLine();
+
+ currentCell=readInput;
+
+ System.out.println("Set:");
+
+ readInput= sc.nextLine();
+
+ formula=readInput;
+
+ spr.put(currentCell, formula);
+
+ System.out.println(spr);
+
+ System.out.println();
+ // System.out.println("Exit? j/n");
+ // readInput= sc.nextLine();
+
+ if(readInput.equals("j"))
+ exit=true;
+
+ }
+
+ while(!exit);
+
+ System.out.println("Programmende.");
+
+ }
+
+
}
\ No newline at end of file
diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java
index f80e156..cb8a34e 100644
--- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java
+++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java
@@ -1,5 +1,6 @@
package de.hs_mannheim.informatik.spreadsheet;
+//
/**
* Part of a simplified spreadsheet system for the PR1 programming lab at Hochschule Mannheim.
* A cell needs to be able to hold a formula and a value
diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java
index acf6548..dacee48 100644
--- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java
+++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java
@@ -6,6 +6,8 @@ import java.io.PrintWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.ArrayList;
+
/**
* A simplified spreadsheet class for the PR1 programming lab at Hochschule Mannheim.
* One aspect worth mentioning is that it only supports long numbers, not doubles.
@@ -127,32 +129,19 @@ public class Spreadsheet {
String sum1;
String sum2;
- if (formula.startsWith("SUMME(")) { // e.g. SUMME(A3:A8) //SUMME(A13:B22)
- /* if(Character.isDigit(formula.charAt(8))) {
- sum1= formula.substring(6, 9);
-
- if(Character.isDigit(formula.charAt(12))) {
- sum2=formula.substring(10,13);
- }else sum2=formula.substring(10,12);
- }else {
- sum1= formula.substring(6, 8);
- if(Character.isDigit(formula.charAt(11))) {
- sum2=formula.substring(9,12);
- }else sum2=formula.substring(9,11);
-
- } */
+ if (formula.startsWith("SUMME(")) // e.g. SUMME(A3:A8) //SUMME(A13:B22)
result = "" + sum(getStartCellName(formula), getEndCellName(formula)); // TODO adapt to cells with two digits
- }
+
else if (formula.startsWith("PRODUKT(")) // e.g. PRODUKT(A3:B9)
- result = "TODO"; // TODO
+ result = "" + prod(getStartCellName(formula),getEndCellName(formula)); // TODO
else if (formula.startsWith("MITTELWERT(")) // e.g. MITTELWERT(A3:A5)
- result = "TODO"; // TODO
+ result = ""+ average(getStartCellName(formula),getEndCellName(formula)); // TODO
else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung
- result = "TODO"; // TODO
+ result = "" + stDev(getStartCellName(formula),getEndCellName(formula)); // TODO
else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert
- result = "TODO"; // TODO
+ result = ""+ min(getStartCellName(formula), getEndCellName(formula));
else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung
- result = "TODO"; // TODO
+ result = ""+ max(getStartCellName(formula), getEndCellName(formula)); // TODO
else if (!formula.isEmpty()) {
try {
result = "" + calculate(formula);
@@ -167,7 +156,7 @@ public class Spreadsheet {
/**
* 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.
- * @param endCellName The name of the cell in the lower right corner of the rectangle.
+ * @param endCellName The name of the cell in the lower right corner ofODO the rectangle.
* @return The sum calculated.
*/
private long sum(String startCellName, String endCellName) {
@@ -178,7 +167,7 @@ public class Spreadsheet {
int endRow=0;
int endCol;
- int sum=0;
+ long sum=0;
int temp;
startRow= getRow(startCellName);
@@ -198,6 +187,178 @@ public class Spreadsheet {
return sum;
}
+
+ private long prod(String startCellName, String endCellName) {
+
+ int startRow=0;
+ int startCol=0;
+
+ int endRow=0;
+ int endCol;
+ long prod=1;
+ long temp;
+
+ startRow= getRow(startCellName);
+ startCol= getCol(startCellName);
+
+ endRow= getRow(endCellName);
+ endCol= getCol(endCellName);
+
+ for(int i= startRow; i<=endRow; i++) {
+ for(int j=startCol; j<=endCol; j++) {
+
+ temp= Integer.parseInt(cells[i][j].getValue());
+ prod=prod*temp;
+ }
+ }
+ return prod;
+ }
+
+ private int average(String startCellName, String endCellName) {
+
+ int startRow=0;
+ int startCol=0;
+
+ int endRow=0;
+ int endCol;
+ int sum=0;
+ int temp;
+ int part=0;
+ int avg=0;;
+
+ startRow= getRow(startCellName);
+ startCol= getCol(startCellName);
+
+ endRow= getRow(endCellName);
+ endCol= getCol(endCellName);
+
+ for(int i= startRow; i<=endRow; i++) {
+ for(int j=startCol; j<=endCol; j++) {
+
+ temp= Integer.parseInt(cells[i][j].getValue());
+ sum=sum+temp;
+ part++;
+ }
+ }
+ avg=sum/part;
+
+ return avg;
+ }
+
+ //Method to calculate the minimum
+
+ private int min(String startCellName, String endCellName) {
+ int startRow=0;
+ int startCol=0;
+
+ int endRow=0;
+ int endCol;
+ int min;
+ int temp;
+
+ startRow= getRow(startCellName);
+ startCol= getCol(startCellName);
+
+ endRow= getRow(endCellName);
+ endCol= getCol(endCellName);
+
+ min=Integer.parseInt(cells[startRow][startCol].getValue());
+
+ for(int i= startRow; i<=endRow; i++) {
+ for(int j=startCol; j<=endCol; j++) {
+
+ temp= Integer.parseInt(cells[i][j].getValue());
+ if(min>temp) {
+ min=temp;
+ }
+ }
+
+
+ }
+ return min;
+ }
+
+
+ //calculate maximum
+
+ private int max(String startCellName, String endCellName) {
+ int startRow=0;
+ int startCol=0;
+
+ int endRow=0;
+ int endCol;
+ int max;
+ int temp;
+
+ startRow= getRow(startCellName);
+ startCol= getCol(startCellName);
+
+ endRow= getRow(endCellName);
+ endCol= getCol(endCellName);
+
+ max=Integer.parseInt(cells[startRow][startCol].getValue());
+
+ for(int i= startRow; i<=endRow; i++) {
+ for(int j=startCol; j<=endCol; j++) {
+
+ temp= Integer.parseInt(cells[i][j].getValue());
+ if(max elements = new ArrayList<>();
+
+ avg= average(startCellName, endCellName);
+
+
+ for(int i= startRow; i<=endRow; i++) {
+ for(int j=startCol; j<=endCol; j++) {
+
+ temp= Integer.parseInt(cells[i][j].getValue());
+ temp=temp-avg;
+ temp= temp*temp;
+ elements.add(temp);
+
+
+ }
+ }
+ avg=0;
+
+ for(int i=0; i