Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/Spreadsheet.class
Binary file not shown.
Binary file modified bin/SpreadsheetTest.class
Binary file not shown.
73 changes: 70 additions & 3 deletions src/Spreadsheet.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,85 @@

public class Spreadsheet {

String[][] matrix = new String [26][1000];
char[] alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

public Spreadsheet(){}

public Spreadsheet(String[][] matrix, char[] alphabet) {
super();
this.matrix = matrix;
this.alphabet = alphabet;
}

public String[][] getMatrix() {
return matrix;
}

public void setMatrix(String[][] matrix) {
this.matrix = matrix;
}

public char[] getAlphabet() {
return alphabet;
}

public void setAlphabet(char[] alphabet) {
this.alphabet = alphabet;
}

public String get(String cell) {
// to be implemented
char letra = cell.charAt(0);
char num = cell.charAt(1);
for (int i = 0; i < alphabet.length; i++) {
if(alphabet[i] == letra){ // You know if its A, B ...

String value = matrix[i][num];

if(value.startsWith("'") && value.endsWith("'")){
return value.substring(1, value.length()-1);
}else if(value.startsWith("'") && value.endsWith("")){
return "#Error";
}else if(value.startsWith("") && value.endsWith("'") && !value.startsWith("=")){
return "#Error";
}else if(value.startsWith("='") && value.endsWith("'"))
return value.substring(2, value.length()-1);


try {
Integer.parseInt(value);
return value;
} catch (NumberFormatException nfe){
return "#Error";
}
}

}
return null;
}



public void set(String cell, String value) {
// to be implemented

char letra = cell.charAt(0);
char num = cell.charAt(1);
for (int i = 0; i < alphabet.length; i++) {
if(alphabet[i] == letra){
matrix[i][num] = value;
}
}
}

public String evaluate(String cell) {
// to be implemented

return null;


}




}
47 changes: 44 additions & 3 deletions tests/SpreadsheetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,50 @@
public class SpreadsheetTest {

@Test
public void test() {
fail("Not yet implemented");
public void testGet() {
Spreadsheet ss = new Spreadsheet();

ss.set("A3", "3");
assertEquals("3", ss.get("A3"));
}


@Test
public void testGet2() {
Spreadsheet ss = new Spreadsheet();

ss.set("A3", "3A");
assertEquals("#Error", ss.get("A3"));
}
@Test
public void testGet3() {
Spreadsheet ss = new Spreadsheet();

ss.set("A3", "'is a String'");
assertEquals("is a String", ss.get("A3"));
}

@Test
public void testGet4() {
Spreadsheet ss = new Spreadsheet();

ss.set("A3", "'3A");
assertEquals("#Error", ss.get("A3"));
}

@Test
public void testGet5() {
Spreadsheet ss = new Spreadsheet();

ss.set("A3", "3A'");
assertEquals("#Error", ss.get("A3"));
}

@Test
public void testGet6() {
Spreadsheet ss = new Spreadsheet();

ss.set("A3", "='a String'");
assertEquals("a String",ss.get("A3"));
}

}