Git Product home page Git Product logo

rajagopal28 / infix-expression-solver Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.25 MB

A Small Swing based Java application which lets us to solve infix mathematical expressions and get results based on some of the best known Object Oriented Design patterns.

License: MIT License

Java 100.00%
java-8 oops-in-java oop-principles factory-pattern immutability infix-evaluation stacks expression-evaluator reusable-functions bodmas-evaluator swing-gui

infix-expression-solver's Introduction

Infix Expression Solver

Java based application to solve infix expressions and get results.

Context

A Small Swing based Java application which lets us to solve infix mathematical expressions and get results based on some of the best known Object Oriented Design patterns.

Flow diagram

Following is the data flow indicating, how the expression parsing and solving works in the given application. Flow diagram

Objective

Create a simple calculator which could be used to do basic operators like addition, subtraction, multiplication, division. The calculator should be able to evaluate multi operand expressions and should follow the bodmas rule. It should also support decimal numbers. Invalid expressions should be handled gracefully.

Approach taken

Expression Solving is an interesting task, especially when it involves multiple operators with difference in priorites, or the order of execution.

  • Stack based expression solving.
  • Bodma's rule of executing the infix mathematical expression. Bodmas
  • Runtime exception creation and handling to ease the data flow with reliably specific exception processing.
  • Efficient handling of data structures by localising them and explicitly creating when their job is done.
  • Factory method pattern applied in creation/fetching of operator. This gives us the flexibility to add a new operators with minimal code changes.
  • Inversion of control by employing the Sub version rule where the Generic Abstraction of Operator is invoked instead of the Specific Concretion of the exact implementation.
  • Re-usability of code employed in all possible places efficiently, especially in the InfixExpressionSolver where the popAndPerformOperation method is reused in a self-contained and efficient way that it can be uses as a conditional operation tying to the other condition, which are varied in places.
  • Immutability enables better efficient handling of data and resources. Immutable classes do promote object proliferation by only disabling object data modification. I have restricted object data change once it got created by not having any setters or Object changes. Either new instance is created or the same value is used through out.
  • Lombok - used annotation based pre-processing to reduce a lot of boilerplate code that can be deferred to compile time.

Possible enhancements

  • Giving ability to work with Unary operators, the current implementation mostly works on the basis that all the operators are binary.
  • Explicit exception handling instead of working with RuntimeExceptions. This way we will have a well-structured way of handling business exceptions effectively and explicitly.

TDD

TDD has been enforced at every stage of the implementation. I have also tried to exercise the text pyramid where I have also covered all the functional testing of the application via unit/functional tests without mocks.

TDD Diagram

Views

Following are the simple depiction of the infix caluclator application.

Default

Default View

Positive Results

View1

View2

Negative Results

View3

View4

View5

Dependencies

Following are the dependent libraries that are used by the solver application. Dependencies

Tests

Following are the list of Unit tests and Integration tests that I have added as part of the application development. Tests

Tests

Test Coverage

TestCoverage

    Developed in Jetbrain's IntelliJ IDE

Running the app

I have created a runnable jar archive that lets us use the application. Which can be downloaded from Here..

build

mvn clean install -U

run

java ./infix-calculator/target/infix-calculator.jar

References

infix-expression-solver's People

Contributors

rajagopal28 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.