From ba4469b358356b21a958594e1d0b1012b14432b7 Mon Sep 17 00:00:00 2001 From: Jan Bachmann <3010330@stud.hs-mannheim.de> Date: Mon, 8 Jan 2024 18:16:08 +0100 Subject: [PATCH] Dateien nach "Axel/src/de/hs_mannheim/informatik/spreadsheet" hochladen test --- .../informatik/spreadsheet/Spreadsheet.java | 71 ++++++++++++++----- 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 8c8dbac..d6cec2f 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -1,5 +1,6 @@ package de.hs_mannheim.informatik.spreadsheet; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; @@ -7,8 +8,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.ArrayList; import java.util.List; - - +import java.util.Scanner; /** * A simplified spreadsheet class for the PR1 programming lab at Hochschule Mannheim. * One aspect worth mentioning is that it only supports long numbers, not doubles. @@ -17,8 +17,7 @@ import java.util.List; */ public class Spreadsheet { Cell[][] cells; - - /** + /* * Constructor that creates a Spreadsheet of size rows * cols. * @param rows number of rows * @param cols number of columns @@ -34,6 +33,23 @@ public class Spreadsheet { for (int c = 0; c < colWithMax26; c++) cells[r][c] = new Cell(); } + /** + * Sets a Spreadsheet of size rows * cols. + * @param rows number of rows + * @param cols number of columns + */ + public void changeSize(int rows, int cols) { + cells = new Cell[0][0]; + + int rowWithMax99= Math.min(rows, 99); + int colWithMax26= Math.min(cols, 26); + + cells = new Cell[rowWithMax99][colWithMax26]; + + for (int r = 0; r < rowWithMax99; r++) + for (int c = 0; c < colWithMax26; c++) + cells[r][c] = new Cell(); + } // ----- /* @@ -55,7 +71,7 @@ public class Spreadsheet { cellName = cellName.toUpperCase(); return get(getRow(cellName), getCol(cellName)); } - private void put(int row, int col, String value) { + void put(int row, int col, String value) { if (!value.startsWith("=")) cells[row][col].setValue(value); else { @@ -67,10 +83,10 @@ public class Spreadsheet { cellName = cellName.toUpperCase(); put(getRow(cellName), getCol(cellName), value); } - private int getCol(String cellName) { + public int getCol(String cellName) { return cellName.charAt(0) - 'A'; } - private int getRow(String cellName) { + public int getRow(String cellName) { if (cellName.length()==3) { int Row = 0; Row +=((cellName.charAt(1)-'0')*10); @@ -86,13 +102,34 @@ 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. */ - public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException { - // TODO: implement this + public void readCsv(String path, String startCellName) throws FileNotFoundException { + Scanner csvIn = new Scanner(new File(path)); + int index= 0; + + while(csvIn.hasNextLine()){ + String line =csvIn.nextLine(); + String all=""; + int filled=0; + for(int i = 0;i args = new ArrayList<>(); for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){ @@ -288,7 +325,7 @@ public class Spreadsheet { * @param endCellName The name of the cell in the lower right corner of the rectangle. * @return The maximum value calculated. */ - private long max(String startCellName, String endCellName) { + public long max(String startCellName, String endCellName) { long res = 0; List args = new ArrayList<>(); for(int j = getRow(startCellName); j<= (getRow(endCellName));j++){