From f922de14d2884572b3a04d2f4df8a57cbba68aba Mon Sep 17 00:00:00 2001 From: 3013050 <3013050@stud.hs-mannheim.de> Date: Tue, 2 Jan 2024 12:08:50 +0100 Subject: [PATCH] JavaDoc comments Added javadoc comments for the remaining methods in Spreadsheet, fixed a small bug in the clearTable method, Added javadoc comments for all methods in Cell --- .../informatik/spreadsheet/Cell.java | 36 ++++++++++-- .../informatik/spreadsheet/Spreadsheet.java | 57 +++++++++++++++++++ 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java index ecbb637..bd35416 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Cell.java @@ -9,28 +9,52 @@ package de.hs_mannheim.informatik.spreadsheet; public class Cell { private String formula = ""; private String value = ""; - + + /** + * Public method to get the formula of the cell. + * @return formula of the cell. + */ public String getFormula() { return formula; } - + + /** + * Public method to set the formula of the cell. + * @param formula formula of the cell. + */ public void setFormula(String formula) { if (!formula.isEmpty()) this.formula = formula.toUpperCase().substring(1); // removes '=' at the beginning } - + + /** + * Public method to get the value of the cell. + * @return value of the cell + */ public String getValue() { return value; } - + + /** + * Public method to set the value of the cell. + * @param value value of the cell. + */ public void setValue(String value) { this.value = value; } - + + /** + * Public method to get cell value as a string. + * @return value as string. + */ public String toString() { return String.format("%4s", value); } - + + /** + * Public method to check if the cell is empty. + * @return true if the cell is empty, false otherwise. + */ public boolean isEmpty() { return value.isEmpty(); } diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 6f6ec43..c46eeb4 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -45,15 +45,33 @@ public class Spreadsheet { // ----- // retrieve or change values of cells + /** + * Private method to get a value from a cell in a spreadsheet. + * @param row The row of the cell. + * @param col The column of the cell. + * @return The value of the cell. + */ private String get(int row, int col) { return cells[row][col].getValue(); } + /** + * Public method to get a value from a cell in a spreadsheet. + * @param cellName The name of the cell. + * @return The value of the cell. + */ public String get(String cellName) { cellName = cellName.toUpperCase(); return get(getRow(cellName), getCol(cellName)); } + /** + * Private methode to put a value into a cell in a spreadsheet. + * @param row The row of the cell. + * @param col The column of the cell. + * @param value The value to put into the cell. + * @return Nothing. + */ private void put(int row, int col, String value) { if (!value.startsWith("=")) cells[row][col].setValue(value); @@ -64,15 +82,32 @@ public class Spreadsheet { } } + /** + * Public method to put a value into a cell in a spreadsheet. + * Calls private methode put. + * @param cellName The name of the cell. + * @param value The value to put into the cell. + * @return Nothing. + */ public void put(String cellName, String value) { cellName = cellName.toUpperCase(); put(getRow(cellName), getCol(cellName), value); } + /** + * Method to get the column of a cell in a spreadsheet. + * @param cellName The name of the cell. + * @return The column of the cell. + */ public int getCol(String cellName) { return cellName.charAt(0) - 'A'; } + /** + * Method to get the row of a cell in a spreadsheet. + * @param cellName The name of the cell. + * @return The row of the cell. + */ public int getRow(String cellName) { String row = ""; for (int i = 1; i < cellName.length(); i++){ @@ -428,6 +463,7 @@ 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 @@ -546,14 +582,26 @@ public class Spreadsheet { // ----- + /** + * Returns the number of rows in the spreadsheet. + * @return amount rows. + */ public int getRowsLCount() { return cells.length; } + /** + * Returns the number of columns in the spreadsheet. + * @return amount columns. + */ public int getColsCount() { return cells[0].length; } + /** + * Clears the spreadsheet, it fills every value and formula to zero. + * @return Nothing. + */ public void clearTable() { int rows = getRowsLCount(); int cols = getColsCount(); @@ -561,10 +609,15 @@ public class Spreadsheet { for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { cells[r][c].setValue(""); + cells[r][c].setFormula(""); } } } + /** + * Loads a special table for testing purposes. + * @return Nothing. + */ public void loadSpecialTable(){ clearTable(); @@ -585,6 +638,10 @@ public class Spreadsheet { put("G5", "3"); } + /** + * Returns a string representation of the spreadsheet. + * @return The spreadsheet as a string. + */ public String toString() { StringBuilder sb = new StringBuilder();