diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index ceacf6f..a85722f 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -17,6 +17,7 @@ public class Spreadsheet { /** * Constructor that creates a Spreadsheet of size rows * cols. + * * @param rows number of rows * @param cols number of columns */ @@ -70,11 +71,12 @@ 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 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. * @return Nothing. - * @exception IOException If path does not exist. + * @throws IOException If path does not exist. */ public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException { // TODO: implement this @@ -82,9 +84,10 @@ public class Spreadsheet { /** * A method for saving data to a CSV file. + * * @param path The file to write. * @return Nothing. - * @exception IOException If path does not exist. + * @throws IOException If path does not exist. */ public void saveCsv(String path) throws FileNotFoundException { PrintWriter out = new PrintWriter(path); @@ -96,7 +99,7 @@ public class Spreadsheet { else out.print(cell.getValue()); - if (cell != row[cells[0].length-1]) + if (cell != row[cells[0].length - 1]) out.print(","); } out.println(); @@ -107,6 +110,7 @@ public class Spreadsheet { /** * This method does the actual evaluation/calcluation of a specific cell + * * @param cellName the name of the cell to be evaluated * @return Nothing. */ @@ -129,7 +133,7 @@ public class Spreadsheet { else if (!formula.isEmpty()) { try { result = "" + calculate(formula); - } catch(ArithmeticException ae) { + } catch (ArithmeticException ae) { result = "exc."; } } @@ -139,8 +143,9 @@ public class Spreadsheet { /** * Method for calculating the sum of a rectangular block of cells, such as from A1 to B3. + * * @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. + * @param endCellName The name of the cell in the lower right corner of the rectangle. * @return The sum calculated. */ private long sum(String startCellName, String endCellName) { @@ -152,9 +157,10 @@ public class Spreadsheet { /** * This method calculates the result of a "normal" algebraic expression. It only needs to support * expressions like =B4 or =2+A3-B2, i.e. only with int numbers and other cells and with plus, - * minus, times, split only. An expression always starts with either a number or a cell name. If it - * continues, it is guaranteed that this is followed by an operator and either a number or a + * minus, times, split only. An expression always starts with either a number or a cell name. If it + * continues, it is guaranteed that this is followed by an operator and either a number or a * cell name again. It is NOT required to implement dot before dash or parentheses in formulas. + * * @param formula The expression to be evaluated. * @return The result calculated. */ @@ -181,22 +187,34 @@ public class Spreadsheet { public String toString() { StringBuilder sb = new StringBuilder(); - sb.append(" "); + sb.append(System.lineSeparator()); + sb.append(" |"); for (int i = 0; i < cells[0].length; i++) { - sb.append(" " + (char)('A'+ i) + " | "); + sb.append(" " + (char) ('A' + i) + " |"); } - int rc = 1; for (Cell[] r : cells) { sb.append(System.lineSeparator()); - sb.append(String.format("%2s", rc++) + ": "); + for (int i = 0; i < cells[0].length; i++) { + sb.append("----------------"); + } + sb.append("------"); + sb.append(System.lineSeparator()); + sb.append(String.format(" " + "%2s", rc++) + " |"); for (Cell c : r) { - sb.append(c + " | "); + sb.append(" " + String.format("%13s", c) + " |"); } } + sb.append(System.lineSeparator()); + for (int i = 0; i < cells[0].length; i++) { + sb.append("----------------"); + } + sb.append("------"); + sb.append(System.lineSeparator()); return sb.toString(); - } + + } } \ No newline at end of file