Coders Packet

Command Line based Calculator for Infix Arithmetic Expression using Java

By Alwis Guru K V

The calculator uses Java to evaluate the infix expression supporting binary operations add, sub, Multiply, division, and modulo entered by the user and report errors in the expression if any.

TITLE: Command Line Interface Calculator using Java

OBJECTIVE: The main objective of this packet is to evaluate infix, i.e., a normal binary arithmetic expression that can be easily recognized by humans.

BUILD TOOLS :

# Java 19

# Maven (with Wrapper)

WORKING:

              It evaluates the infix Depression entered by the user as a string. The string can contain parenthesis. The program can identify invalid parenthesis and will report an error. Binary operators including +, -, *, /, % are supported. 

Example for Infix expression: 3+2, 5*6+2-18/6

Infix notation is easily recognized by humans using any precedence rule. In this Java packet, two stacks have been used to directly evaluate the infix expression without changing it into a prefix notation that can be easily recognized by computers. 

A static hashmap is used rather than a switch case to check for the operator precedence and their operations. Computation for each operation is evaluated with Interface to add your features into the packet easily.

 

STEPS TO RUN :

##Command Line

# 'cd' into the project root directory and run the command based on your OS

# Linux/Mac

./mvnw compile java:exec

# Windows

mvnw.cmd compile exec:java

HOW TO  : 

Type exit to end the session.

USAGE :

# You can use this packet for your App, desktop application to solve the logic just by developing the frontend UI.

CalC_1

MODIFICATION :

For new operators you desire,

1. Implemets the Compute interface for the operation

2. Add the operator precedence to the precedence map

3. Add the operation class to the Operator map.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Alwis Guru K V (kvalwis)

Download packets of source code on Coders Packet