1
0
Fork 0

Compare commits

..

No commits in common. "95913e847f0b4fcb3c26d10ce39e8643f508c4c8" and "091418cbdee43d754b604420aa70090ab8b0ab0c" have entirely different histories.

4 changed files with 113 additions and 173 deletions

View File

@ -1,20 +1,100 @@
Hallo,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
1,,7,,,,,,,,,,,,,,,,, 1,,,,,,,,,,,,,,,,,,,,,,,,,,
55,7,,4,,,,,,,,,,,,,,,, 123,,,,,,,,,,,,,,,,,,,,,,,,,,
9,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
1,,,,,,,,=7*6,=7*6,,,,,,,,,, ,,,,,,,,,=7*6,,,,,,,,,,,,,,,,,
,,,,,,,,,=3/2,,,,,,,,,, ,,,,,,,,,=3/2,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
,=41+A2,,,,,,,,,,,,,,,,,, ,=41+A2,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,LL,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,Z1,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,
,,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,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,

1 Hallo
2 1 1 7
3 55 7 123 4
4 9
5 1 =7*6 =7*6 =7*6
6 =3/2 =3/2
7
8
9 =41+A2 =41+A2
10
11
12 LL
13
14
15 Z1
16
17
18
19
20 20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

View File

@ -70,23 +70,14 @@ public class Axel {
System.out.println("Möchten Sie weiter machen(j/n)?"); System.out.println("Möchten Sie weiter machen(j/n)?");
} else if (eingabe.equals("n")) { } else if (eingabe.equals("n")) {
//System.out.println("Das Programm wird beendet"); System.out.println("Das Programm wird beendet");
break; break;
} else { } else {
System.out.println("Falsche eingabe bitte erneut versuchen"); System.out.println("Falsche eingabe bitte erneut versuchen");
} }
} while (true); } while (true);
System.out.println("Möchten Sie die Änderungen an der Tabelle speichern? (j/n)");
eingabe = sc.nextLine();
if(eingabe.equals("j"))
{
spr.saveCsv("C:\\Users\\sebas\\IdeaProjects\\PR1-Spreadsheet\\Axel\\resources\\zahlen.csv"); spr.saveCsv("C:\\Users\\sebas\\IdeaProjects\\PR1-Spreadsheet\\Axel\\resources\\zahlen.csv");
System.out.println("Das Programm wird beendet");
} else{
System.out.println("Tabelle wird nicht gespeichert. Das Programm wird beendet");
}
// Speichern der Tabelle bzw Inhalt der Textdatei(Änderungen) // Speichern der Tabelle bzw Inhalt der Textdatei(Änderungen)
} }
} }

View File

@ -1,7 +1,5 @@
package de.hs_mannheim.informatik.spreadsheet; package de.hs_mannheim.informatik.spreadsheet;
import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@ -105,12 +103,6 @@ public class Spreadsheet {
} }
} }
/**
*
* @param path Dateipfad der Datei die von der Methode ausgelesen werden soll
* @return lines
* @throws FileNotFoundException
*/
public static ArrayList<String> readFile(String path) throws FileNotFoundException { public static ArrayList<String> readFile(String path) throws FileNotFoundException {
ArrayList<String> lines = new ArrayList<>(); ArrayList<String> lines = new ArrayList<>();
Scanner sc = new Scanner(new File(path)); Scanner sc = new Scanner(new File(path));
@ -153,10 +145,9 @@ public class Spreadsheet {
} }
/** /**
* Methode welche die Eingabe überprüft und anhand dessen, dann auf abgebildete Methoden zugreift * This method does the actual evaluation/calcluation of a specific cell
* und das Ergebnis wiedergibt * @param cellName the name of the cell to be evaluated
* @param row steht für die Zeile * @return Nothing.
* @param col steht für die Spalte
*/ */
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();
@ -208,13 +199,6 @@ public class Spreadsheet {
return result; return result;
} }
/**
* Methode zum berechnen des Produkts eines viereckigen Blocks aus Zellen. Beispiel A2 bis B2
* @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 das Produkt. Hier result
*/
private long multiplier(String startCellName, String endCellName) { private long multiplier(String startCellName, String endCellName) {
int startRow = getRow(startCellName); int startRow = getRow(startCellName);
@ -232,12 +216,6 @@ public class Spreadsheet {
return result; return result;
} }
/**
* Methode zum berechnen des Mittelwerts eines viereckigen Blocks aus Zellen. Beispiel A2 bis B2
* @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 der Mittelwert. Hier result
*/
private long mittelwert(String startCellName, String endCellName) { private long mittelwert(String startCellName, String endCellName) {
int startRow = getRow(startCellName); int startRow = getRow(startCellName);
@ -259,12 +237,6 @@ public class Spreadsheet {
return result; return result;
} }
/**
* Methode zum berechnen des Minimums eines viereckigen Blocks aus Zellen. Beispiel A2 bis B2
* @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 die kleinste Zahl. Hier result
*/
private long min(String startCellName, String endCellName) { private long min(String startCellName, String endCellName) {
int startRow = getRow(startCellName); int startRow = getRow(startCellName);
int startCol = getCol(startCellName); int startCol = getCol(startCellName);
@ -276,8 +248,7 @@ public class Spreadsheet {
for (int j = startCol; j <= endCol; j++) { for (int j = startCol; j <= endCol; j++) {
result = (Integer.parseInt(cells[i][j].getValue())); result = (Integer.parseInt(cells[i][j].getValue()));
if(result > (Integer.parseInt(cells[i][j].getValue()))) //größer result für min Wert if(result > (Integer.parseInt(cells[i][j].getValue()))) {
{
result = (Integer.parseInt(cells[i][j].getValue())); result = (Integer.parseInt(cells[i][j].getValue()));
} }
@ -285,12 +256,7 @@ public class Spreadsheet {
} }
return result; return result;
} }
/**
* Methode zum berechnen des Maximums eines viereckigen Blocks aus Zellen. Beispiel A2 bis B2
* @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 das Maximum. Hier result
*/
private long max(String startCellName, String endCellName) { private long max(String startCellName, String endCellName) {
int startRow = getRow(startCellName); int startRow = getRow(startCellName);
int startCol = getCol(startCellName); int startCol = getCol(startCellName);
@ -301,8 +267,7 @@ public class Spreadsheet {
for (int i = startRow; i <= endRow; i++) { for (int i = startRow; i <= endRow; i++) {
for (int j = startCol; j <= endCol; j++) { for (int j = startCol; j <= endCol; j++) {
if(result < (Integer.parseInt(cells[i][j].getValue()))) // kleiner result für max Wert if(result < (Integer.parseInt(cells[i][j].getValue()))) {
{
result = (Integer.parseInt(cells[i][j].getValue())); result = (Integer.parseInt(cells[i][j].getValue()));
} }
@ -324,94 +289,24 @@ public class Spreadsheet {
* @param formula The expression to be evaluated. * @param formula The expression to be evaluated.
* @return The result calculated. * @return The result calculated.
*/ */
private long calculate(String formula) throws ArithmeticException {
public long calculate(String formula) throws ArithmeticException {
Matcher m = Pattern.compile("([A-Z][0-9]*)|[-\\+\\*/]|[0-9]*").matcher(formula); Matcher m = Pattern.compile("([A-Z][0-9]*)|[-\\+\\*/]|[0-9]*").matcher(formula);
long result = 0; long res = 0;
int zwischenspeicher = 0;
int counter = 0;
int newNumber = 0;
// TODO implement // TODO implement
// uncomment the following to see an example how the elements of a formula can be accessed
while (m.find()) { // m.find() must always be used before m.group() while (m.find()) { // m.find() must always be used before m.group()
String s = m.group(); String s = m.group();
if (!s.isEmpty()) { if (!s.isEmpty()) {
//System.out.println(s); System.out.println(s);
counter++;
switch (counter){
case 1:
try {
result = Integer.parseInt(s);
}catch (Exception ignored){
result = Integer.parseInt(get(s));
}
break;
case 2:
switch(s) {
case "+":
zwischenspeicher = 1;
break;
case "-":
zwischenspeicher = 2;
break;
case "*":
zwischenspeicher = 3;
break;
case "/":
zwischenspeicher = 4;
break;
default:
System.out.println("ERROR");
break;
}
break;
case 3:
try {
newNumber = Integer.parseInt(s);
}catch (Exception ignored){
newNumber = Integer.parseInt(get(s));
}
result = rechner(result, zwischenspeicher, newNumber);
counter = 1;
break;
default:
System.out.println("ERROR");
break;
}
} }
} }
return result; return res;
} }
/**
*
* @param a steht für die Zahl "a"
* @param auswahl steht für die entsprechende Rechnung
* @param b steht für die Zahl "b"
* @return die Rechnung
*/
public static long rechner(long a, int auswahl, int b) {
switch(auswahl){
case 1:
return a + b;
case 2:
return a - b;
case 3:
return a * b;
case 4:
return a / b;
default:
System.out.println("ERROR");
break;
}
return 0;
}
// ----- // -----
public String toString() { public String toString() {

View File

@ -1,26 +0,0 @@
package de.hs_mannheim.informatik.spreadsheet;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
class SpreadsheetTest {
@org.junit.jupiter.api.Test
void testCalculate() {
Spreadsheet spr = new Spreadsheet(25,25); // Irgendeine Größe einstellen des Spreadsheets
assertEquals(spr.calculate("2+2"), 4);
assertEquals(spr.calculate("3*3"), 9);
assertEquals(spr.calculate("6/2"), 3);
spr.put("A1", "6");
spr.put("A2", "2");
assertEquals(spr.calculate("A1+A2"), 8);
assertEquals(spr.calculate("A1*A2"), 12);
assertEquals(spr.calculate("A1/A2"), 3);
}
}