From 21eefb6d9128f4740aff4b31c1a28e48fe873978 Mon Sep 17 00:00:00 2001 From: 3012330 <3012330@stud.hs-mannheim.de> Date: Wed, 3 Jan 2024 15:01:55 +0100 Subject: [PATCH] =?UTF-8?q?Maximale=20Gr=C3=B6=C3=9Fe=20von=20Spreadsheet?= =?UTF-8?q?=20(und=20minimale,=20dass=20es=20immer=20mindestens=201=20Spal?= =?UTF-8?q?te/Zeile=20hat)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Axel/resources/zahlen.csv | 14 ++++++++---- Axel/resources/zahlen2.csv | 10 +++++++++ .../informatik/spreadsheet/Axel.java | 14 +++++++++--- .../informatik/spreadsheet/Spreadsheet.java | 22 +++++++++++++------ 4 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 Axel/resources/zahlen2.csv diff --git a/Axel/resources/zahlen.csv b/Axel/resources/zahlen.csv index 1ec60e0..0f60336 100644 --- a/Axel/resources/zahlen.csv +++ b/Axel/resources/zahlen.csv @@ -1,4 +1,10 @@ -1,2 -3,4 -5,6 -7,8 +123,,,,,,,,,1111 +1,,,,,,,,, +,,,,,,,,, +,,,,,,,,, +,,,,,,,,,=7*6 +,,,,,,,,,=3/2 +,,,,,,,,, +,,,,,,,,, +,=41+A2,,,,,,,, +,,,,,,,,, diff --git a/Axel/resources/zahlen2.csv b/Axel/resources/zahlen2.csv new file mode 100644 index 0000000..5d304d0 --- /dev/null +++ b/Axel/resources/zahlen2.csv @@ -0,0 +1,10 @@ +,,,,,,,,, +1,,,,,,,,, +123,,,,,,,,, +,,,,,,,,, +,,,,,,,,,=7*6 +,,,,,,,,,=3/2 +,,,,,,,,, +,,,,,,,,, +,=41+A2,,,,,,,, +,,,,,,,,, diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java index df720b3..e844b60 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Axel.java @@ -12,16 +12,24 @@ public class Axel { public static void main(String[] args) throws FileNotFoundException { Spreadsheet spr = new Spreadsheet(10,10); - spr.put("A3", "123"); + spr.put("A1", "123"); spr.put("A2", "1"); spr.put("B9", "=41+A2"); spr.put("J5", "=7*6"); spr.put("J6", "=3/2"); + + spr.put("J10", "1111"); // Das Programm konnte keine Zellen mit 2 Stellen (>9) einlesen! (-> Programm macht es an Stelle 1 statt 10) System.out.println(spr); - - spr.saveCsv("/tmp/test.csv"); + + spr.saveCsv("C:\\Users\\flori\\IdeaProjects\\PR1-Spreadsheet\\Axel\\resources\\zahlen.csv"); + + + + //spr.readCsv("C:\\Users\\flori\\IdeaProjects\\PR1-Spreadsheet\\Axel\\resources\\zahlen2.csv", ',',"A1"); + //System.out.println(spr); + // TODO: You might want to put "UI loop" for entering value and formulas here resp. in some UI methods. } diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index de46be0..312e2bd 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -24,6 +24,18 @@ public class Spreadsheet { // TODO limit the maximum size on 99 (1..99) rows and 26 (A..Z) columns + if (rows > 99) { + rows = 99; + } else if (rows <= 0) { + rows = 1; + } + + if (cols > 26) { + cols = 26; + } else if (cols <= 0) { + cols = 1; + } + cells = new Cell[rows][cols]; for (int r = 0; r < rows; r++) @@ -57,13 +69,9 @@ public class Spreadsheet { put(getRow(cellName), getCol(cellName), value); } - private int getCol(String cellName) { - return cellName.charAt(0) - 'A'; - } + private int getCol(String cellName) {return cellName.charAt(0) - 'A';} - private int getRow(String cellName) { - return cellName.charAt(1) - '1'; - } + private int getRow(String cellName) {return cellName.charAt(1) - '1';} // ----- // business logic @@ -72,7 +80,7 @@ public class Spreadsheet { * A method for reading in data from a CSV file. * @param path The file to read. * @param separator The char used to split up the input, e.g. a comma or a semicolon. - * @param starCellName The upper left cell where data from the CSV file should be inserted. + * @param startCellName The upper left cell where data from the CSV file should be inserted. * @return Nothing. * @exception IOException If path does not exist. */