diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index 65a313a..ae133ea 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -13,18 +13,24 @@ public class Axel { public static void main(String[] args) throws FileNotFoundException { String cell, in; int rows, cols; + Spreadsheet spr=new Spreadsheet(99,26); Scanner kb = new Scanner(System.in); - System.out.print("Rows:"); - rows=Integer.parseInt(kb.nextLine()); - System.out.print("Cols:"); - cols=Integer.parseInt(kb.nextLine()); - Spreadsheet spr=new Spreadsheet(rows,cols); - //spr.put("A3", "3"); - //spr.put("A2", "2"); - spr.put("A1","=19+4"); - spr.put("B9", "=41+A2"); - spr.put("J5", "=7*6"); - spr.put("J6", "=4/2"); + System.out.printf("1. New\n" + + "2. Load\n" + + "Eingabe:"); + in=kb.nextLine(); + switch(in) { + case("1"): + System.out.print("Rows:"); + rows=Integer.parseInt(kb.nextLine()); + System.out.print("Cols:"); + cols=Integer.parseInt(kb.nextLine()); + spr=new Spreadsheet(rows,cols); + case("2"): + System.out.print("File Name:"); + in=kb.nextLine(); + spr.readCsv("tmp/"+in); + } while(true) { System.out.println(spr); diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 8feb0e0..ceca665 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -1,8 +1,10 @@ package de.hs_mannheim.informatik.spreadsheet; import java.io.FileNotFoundException; +import java.io.File; import java.io.IOException; import java.io.PrintWriter; +import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -80,8 +82,18 @@ public class Spreadsheet { * @return Nothing. * @exception IOException If path does not exist. */ - public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException { - // TODO: implement this + public void readCsv(String path) throws FileNotFoundException { + 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 cell : row) { - if (!cell.getFormula().isEmpty()) - out.print("=" + cell.getFormula()); - else - out.print(cell.getValue()); - + out.print(cell.getValue()); if (cell != row[cells.length-1]) out.print(","); } @@ -284,31 +292,31 @@ public class Spreadsheet { switch(operation) { case("+"): res+=Integer.parseInt(get(s)); - break; + break; case("-"): res-=Integer.parseInt(get(s)); - break; + break; case("*"): res*=Integer.parseInt(get(s)); - break; + break; case("/"): res/=Integer.parseInt(get(s)); - break; + break; } }else { switch(operation) { case("+"): res+=Integer.parseInt(s); - break; + break; case("-"): res-=Integer.parseInt(s); - break; + break; case("*"): res*=Integer.parseInt(s); - break; + break; case("/"): res/=Integer.parseInt(s); - break; + break; } }