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..51a206f 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..6de15d8 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..006bc4e 100644 --- a/src/Spreadsheet.java +++ b/src/Spreadsheet.java @@ -1,18 +1,83 @@ +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class Spreadsheet { + private String excel[][] = new String[26][26]; + + private int AlphabetToNum(String str){ + char[] ch = str.toCharArray(); + for(char c : ch) + { + int temp = (int)c; + int temp_integer = 64; //for upper case + if(temp<=90 & temp>=65) + return temp-temp_integer; + } + return 0; + } + + private boolean isCell(String split) { + // TODO Auto-generated method stub + String[] str = split.split(""); + + Pattern p = Pattern.compile("{upper}"); + Pattern p2 = Pattern.compile("{digit}"); + Matcher m = p.matcher(str[0]); + Matcher m2 = p2.matcher(str[1]); + if (m.find() & m2.find()) + return true; + return false; + } + public String get(String cell) { - // to be implemented - return null; + + String[] str = cell.split(""); + + return excel[AlphabetToNum(str[0])][Integer.parseInt(str[1])]; + } public void set(String cell, String value) { - // to be implemented + + String[] str = cell.split(""); + excel[AlphabetToNum(str[0])][Integer.parseInt(str[1])] = value; } public String evaluate(String cell) { - // to be implemented - return null; + int resultNum=0; + int count=0; + String result=""; + + String data = get(cell); + String[] str = data.split(""); + + for(int i=0; i