forked from hummel/PR1-Spreadsheet
Compare commits
No commits in common. "95913e847f0b4fcb3c26d10ce39e8643f508c4c8" and "091418cbdee43d754b604420aa70090ab8b0ab0c" have entirely different histories.
95913e847f
...
091418cbde
|
@ -1,20 +1,100 @@
|
|||
Hallo,,,,,,,,,,,,,,,,,,,
|
||||
1,,7,,,,,,,,,,,,,,,,,
|
||||
55,7,,4,,,,,,,,,,,,,,,,
|
||||
9,,,,,,,,,,,,,,,,,,,
|
||||
1,,,,,,,,=7*6,=7*6,,,,,,,,,,
|
||||
,,,,,,,,,=3/2,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,
|
||||
,=41+A2,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,LL,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,Z1,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,
|
||||
20,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
1,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
123,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,=7*6,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,=3/2,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,=41+A2,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,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,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
|
|
|
|
@ -70,23 +70,14 @@ public class Axel {
|
|||
System.out.println("Möchten Sie weiter machen(j/n)?");
|
||||
|
||||
} else if (eingabe.equals("n")) {
|
||||
//System.out.println("Das Programm wird beendet");
|
||||
System.out.println("Das Programm wird beendet");
|
||||
break;
|
||||
|
||||
} else {
|
||||
System.out.println("Falsche eingabe bitte erneut versuchen");
|
||||
}
|
||||
} 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");
|
||||
System.out.println("Das Programm wird beendet");
|
||||
} else{
|
||||
System.out.println("Tabelle wird nicht gespeichert. Das Programm wird beendet");
|
||||
}
|
||||
|
||||
spr.saveCsv("C:\\Users\\sebas\\IdeaProjects\\PR1-Spreadsheet\\Axel\\resources\\zahlen.csv");
|
||||
// Speichern der Tabelle bzw Inhalt der Textdatei(Änderungen)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package de.hs_mannheim.informatik.spreadsheet;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
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 {
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
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
|
||||
* und das Ergebnis wiedergibt
|
||||
* @param row steht für die Zeile
|
||||
* @param col steht für die Spalte
|
||||
* This method does the actual evaluation/calcluation of a specific cell
|
||||
* @param cellName the name of the cell to be evaluated
|
||||
* @return Nothing.
|
||||
*/
|
||||
private void evaluateCell(int row, int col) {
|
||||
String formula = cells[row][col].getFormula();
|
||||
|
@ -208,13 +199,6 @@ public class Spreadsheet {
|
|||
|
||||
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) {
|
||||
|
||||
int startRow = getRow(startCellName);
|
||||
|
@ -232,12 +216,6 @@ public class Spreadsheet {
|
|||
|
||||
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) {
|
||||
|
||||
int startRow = getRow(startCellName);
|
||||
|
@ -259,12 +237,6 @@ public class Spreadsheet {
|
|||
|
||||
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) {
|
||||
int startRow = getRow(startCellName);
|
||||
int startCol = getCol(startCellName);
|
||||
|
@ -276,8 +248,7 @@ public class Spreadsheet {
|
|||
for (int j = startCol; j <= endCol; j++) {
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
|
@ -285,12 +256,7 @@ public class Spreadsheet {
|
|||
}
|
||||
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) {
|
||||
int startRow = getRow(startCellName);
|
||||
int startCol = getCol(startCellName);
|
||||
|
@ -301,8 +267,7 @@ public class Spreadsheet {
|
|||
for (int i = startRow; i <= endRow; i++) {
|
||||
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()));
|
||||
}
|
||||
|
||||
|
@ -324,94 +289,24 @@ public class Spreadsheet {
|
|||
* @param formula The expression to be evaluated.
|
||||
* @return The result calculated.
|
||||
*/
|
||||
|
||||
public long calculate(String formula) throws ArithmeticException {
|
||||
private long calculate(String formula) throws ArithmeticException {
|
||||
Matcher m = Pattern.compile("([A-Z][0-9]*)|[-\\+\\*/]|[0-9]*").matcher(formula);
|
||||
|
||||
long result = 0;
|
||||
int zwischenspeicher = 0;
|
||||
int counter = 0;
|
||||
int newNumber = 0;
|
||||
long res = 0;
|
||||
|
||||
// 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()
|
||||
String s = m.group();
|
||||
if (!s.isEmpty()) {
|
||||
//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;
|
||||
}
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue