1
0
Fork 0

vorheriges

main
ERANZER 2024-01-09 14:32:26 +01:00
parent 0a6ad90343
commit 7cf156f229
2 changed files with 40 additions and 26 deletions

View File

@ -13,18 +13,24 @@ public class Axel {
public static void main(String[] args) throws FileNotFoundException { public static void main(String[] args) throws FileNotFoundException {
String cell, in; String cell, in;
int rows, cols; int rows, cols;
Spreadsheet spr=new Spreadsheet(99,26);
Scanner kb = new Scanner(System.in); Scanner kb = new Scanner(System.in);
System.out.print("Rows:"); System.out.printf("1. New\n"
rows=Integer.parseInt(kb.nextLine()); + "2. Load\n"
System.out.print("Cols:"); + "Eingabe:");
cols=Integer.parseInt(kb.nextLine()); in=kb.nextLine();
Spreadsheet spr=new Spreadsheet(rows,cols); switch(in) {
//spr.put("A3", "3"); case("1"):
//spr.put("A2", "2"); System.out.print("Rows:");
spr.put("A1","=19+4"); rows=Integer.parseInt(kb.nextLine());
spr.put("B9", "=41+A2"); System.out.print("Cols:");
spr.put("J5", "=7*6"); cols=Integer.parseInt(kb.nextLine());
spr.put("J6", "=4/2"); spr=new Spreadsheet(rows,cols);
case("2"):
System.out.print("File Name:");
in=kb.nextLine();
spr.readCsv("tmp/"+in);
}
while(true) { while(true) {
System.out.println(spr); System.out.println(spr);

View File

@ -1,8 +1,10 @@
package de.hs_mannheim.informatik.spreadsheet; package de.hs_mannheim.informatik.spreadsheet;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Scanner;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -80,8 +82,18 @@ public class Spreadsheet {
* @return Nothing. * @return Nothing.
* @exception IOException If path does not exist. * @exception IOException If path does not exist.
*/ */
public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException { public void readCsv(String path) throws FileNotFoundException {
// TODO: implement this Scanner file=new Scanner(new File(path));
String[] rowRead;
int row=0;
while(file.hasNextLine()) {
rowRead=file.nextLine().split(",");
for(int col=0;col<=rowRead.length-1;col++) {
put(row,col,rowRead[col]);
}
row++;
}
} }
/** /**
@ -95,11 +107,7 @@ public class Spreadsheet {
for (Cell[] row : cells) { for (Cell[] row : cells) {
for (Cell cell : row) { for (Cell cell : row) {
if (!cell.getFormula().isEmpty()) out.print(cell.getValue());
out.print("=" + cell.getFormula());
else
out.print(cell.getValue());
if (cell != row[cells.length-1]) if (cell != row[cells.length-1])
out.print(","); out.print(",");
} }
@ -284,31 +292,31 @@ public class Spreadsheet {
switch(operation) { switch(operation) {
case("+"): case("+"):
res+=Integer.parseInt(get(s)); res+=Integer.parseInt(get(s));
break; break;
case("-"): case("-"):
res-=Integer.parseInt(get(s)); res-=Integer.parseInt(get(s));
break; break;
case("*"): case("*"):
res*=Integer.parseInt(get(s)); res*=Integer.parseInt(get(s));
break; break;
case("/"): case("/"):
res/=Integer.parseInt(get(s)); res/=Integer.parseInt(get(s));
break; break;
} }
}else { }else {
switch(operation) { switch(operation) {
case("+"): case("+"):
res+=Integer.parseInt(s); res+=Integer.parseInt(s);
break; break;
case("-"): case("-"):
res-=Integer.parseInt(s); res-=Integer.parseInt(s);
break; break;
case("*"): case("*"):
res*=Integer.parseInt(s); res*=Integer.parseInt(s);
break; break;
case("/"): case("/"):
res/=Integer.parseInt(s); res/=Integer.parseInt(s);
break; break;
} }
} }