Spreadsheet Calculator

A simple textual spreadsheet calculator based on java. Developed for a coding challenge.

Problem Description

Unable to share problem description and company's name as its was marked Confidential and asked not to distribute.

Supported Functionalities

  1. Supports operations on negative and positive Integers and cell based references.
  2. Detects and reports circular dependencies between cells
  3. Supported Operations as of now:
    1. Additon +
    2. Subtraction -
    3. Multiplication *
    4. Division /
    5. Increment ++
    6. Decrement --

File Description

Filename Description
Token.java Abstract token class
OperatorToken.java Concrete class derived from Token.java to represent operators as Tokens
ReferenceToken.java Concrete class derived from Token.java to represent Cell References as Tokens
ValueToken.java Concrete class derived from Token.java to represent Values (operands) as Tokens
TokenFactory.java Factory to get appropriate type of Token from the above list of tokens
Cell.java Class which represents the cells in a spreadsheet's workbook
Operators.java Class to represent all the supported operators and their operations.
CircularDependencyException.java Custom Exception class for Circular Dependency
WorkBook.java Composition over Cells to provides a matrix of cells and support their evaluation
Spreadsheet.java The main spreadsheet calculation class
Utils.java Class containing some utility functions
PrettyPrinter.java Class for priting a matrix in a pretty format. Source code taken from here
SpreadsheetTest.java A raw Test class just to bundle up running tests against different input files

How to Run

Clone the repo and from the parent directory Spreadsheet-Calculator run the following commands

  • Compile

Spreadsheet-Calculator$ javac src/main/java/com/rohitsinha/codingchallenge/*.java

  • Run

Spreadsheet-Calculator$ cat input1.txt | java -classpath src/ main.java.com.rohitsinha.codingchallenge.Spreadsheet

  • For prettyPrint Results

Spreadsheet-Calculator$ cat input1.txt | java -classpath src/ main.java.com.rohitsinha.codingchallenge.Spreadsheet -p

Examples

1. input1.txt

Inputs:

1 2 3
A A2 4 5 * A1
B A1 B2 / 2 + 3 39 B1 B2 * /

Results:

20.00000

20.00000

20.00000

8.66667

3.00000

1.50000

PrettyPrint Results:

1 2 3
A 20.00000 20.00000 20.00000
B 8.66667 3.00000 1.50000

2. input2.txt

Inputs:

1 2 3
A A2 4 5 * A1 / A1
B A1 B2 / 2 + 3 39 B1 B2 * /

Results:

Not Evaluated (Circular Dependency)

Not Evaluated (Circular Dependency)

Not Evaluated

Not Evaluated (Circular Dependency)

3.00000

Not Evaluated

PrettyPrint Results:

1 2 3
A Not Evaluated (Circular Dependency) Not Evaluated (Circular Dependency) Not Evaluated
B Not Evaluated (Circular Dependency) 3.00000 Not Evaluated

Testing

The program has been tested on following operating systems:

  1. Mac OSX 10.9.2

##To Do

  1. Add function headers and improve code documentation. This complete project was developed in less than 4 hours so the documentation kind of sucks :/

##Version 1.0 beta

##Contact Information Please report any bugs or issues to: talktorohit54@gmail.com

##License MIT License