1
0
Fork 0

Spreadsheet toString updated.

pull/1/head
selim 2023-12-26 03:09:42 +01:00
parent ada8f538a2
commit 6f6cb59f08
1 changed files with 33 additions and 15 deletions

View File

@ -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 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);
@ -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.
*/
@ -139,6 +143,7 @@ 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.
* @return The sum calculated.
@ -155,6 +160,7 @@ public class Spreadsheet {
* 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) + " |");
}
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();
}
}
}