diff --git a/.besouro/20161013143006626/actions.txt b/.besouro/20161013143006626/actions.txt new file mode 100644 index 0000000..e69de29 diff --git a/.besouro/20161013143006626/zorroEpisodes.txt b/.besouro/20161013143006626/zorroEpisodes.txt new file mode 100644 index 0000000..e69de29 diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..2079672 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,2 @@ +/Spreadsheet.class +/SpreadsheetTest.class diff --git a/bin/Spreadsheet.class b/bin/Spreadsheet.class index 92b411f..274b223 100644 Binary files a/bin/Spreadsheet.class and b/bin/Spreadsheet.class differ diff --git a/bin/SpreadsheetTest.class b/bin/SpreadsheetTest.class index e7086bd..1ecbc77 100644 Binary files a/bin/SpreadsheetTest.class and b/bin/SpreadsheetTest.class differ diff --git a/src/Spreadsheet.java b/src/Spreadsheet.java index e4f120b..56b8813 100644 --- a/src/Spreadsheet.java +++ b/src/Spreadsheet.java @@ -1,18 +1,124 @@ +import java.awt.Event; +import java.util.ArrayList; public class Spreadsheet { + public String[][] matrix = new String[27][1000]; + public static char[] abecedario = new char[26]; + + + + + public Spreadsheet() { + super(); + + int a = (int) 'A'; + + for(int i = 0; i < abecedario.length; i++) + { + abecedario[i] = (char) (a + i); + } + + } + + + public char intToAbc(int num){ + return abecedario[num]; + + } + public int abcToInt(char a){ + int num=-1; + for(int i = 0; i < abecedario.length; i++) + { + if (abecedario[i]== a) { + num=i; + break; + } + } + + return num; + + } public String get(String cell) { - // to be implemented - return null; + + int row= abcToInt(cell.charAt(0)); + cell= cell.substring(1); + int column = Integer.valueOf(cell); + + return matrix[row][column]; } - + public void set(String cell, String value) { - // to be implemented + int row= abcToInt(cell.charAt(0)); + cell= cell.substring(1); + int column = Integer.valueOf(cell); + matrix[row][column]= value; + } - + public String evaluate(String cell) { - // to be implemented - return null; + String value=""; + + if (get(cell).startsWith("=")) { + + if (get(cell).startsWith("='") && get(cell).endsWith("'")) { + value+= get(cell).substring(2, get(cell).length()-1); + }else if (isCell(get(cell).substring(1))) { + String nextCell=get(cell).substring(1); + + if (isNumeric(get(nextCell))) { + value+=get(nextCell); + }else value.equals("#Error1"); + + + if (get(nextCell).substring(1).equals(cell)) { + value+="#Circula"; + + } + + + }else return "#Error2"; + + + + }else{ + + if (isNumeric(get(cell))) { + + value+= get(cell); + }else if (get(cell).startsWith("'") && get(cell).endsWith("'")) { + value+= get(cell).substring(1, get(cell).length()-1); + }else return "#Error3"; + + } + return value; + } + + + // si = + String '' --> devuelve el string + // si = + String a medias 'o' --> devuelve #error + // si = + Letra+Numeros A13--> devuelve le valor de esa celda + + private static boolean isNumeric(String cadena){ + try { + Integer.parseInt(cadena); + return true; + } catch (NumberFormatException nfe){ + return false; + } + } + private static boolean isCell(String cadena){ + if (cadena.charAt(0)>='A'&&cadena.charAt(0)<='Z' && isNumeric(cadena.substring(1))&& cadena.charAt(1)!='-') { + return true; + }else return false; + } + + public static void main(String[] args) { + + Spreadsheet sp= new Spreadsheet(); + sp.set("B13","=B16"); + sp.set("B16", "5"); + System.out.println(sp.evaluate("B13")); + } - } diff --git a/tests/SpreadsheetTest.java b/tests/SpreadsheetTest.java index 9e0936a..80b9790 100644 --- a/tests/SpreadsheetTest.java +++ b/tests/SpreadsheetTest.java @@ -9,7 +9,37 @@ public class SpreadsheetTest { @Test public void test() { fail("Not yet implemented"); - + + } + + + + @Test + public void testGet() { + boolean ok=false; + Spreadsheet sp= new Spreadsheet(); + sp.set("B13", "Jon"); + if ("Jon"== sp.get("B13")) { + ok=true; + } + assertTrue(ok); + } + @Test + public void testEvaluate() { + boolean ok=false; + Spreadsheet sp= new Spreadsheet(); + sp.set("B13", "-234"); + sp.evaluate("B13"); + if (sp.evaluate("B13").equals("true") ) { + ok=true; + System.out.println("iep"); + } + assertTrue(ok); + + } + + + }