Coder Social home page Coder Social logo

opengenus / calculator-in-java Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 2.0 7 KB

Calculator console application in Java

Home Page: https://iq.opengenus.org/calculator-console-application-in-java/

Java 100.00%
calculator java opengenus opengenus-internship

calculator-in-java's Introduction

Calculator Console Application

This is a simple calculator application that takes a mathematical expression as input and evaluates it. The application is written in Java and has two main files: main.java and helper.java.

main.java

This file contains the main function, which takes input from the user, calls the evaluate method from the Helper class, and prints the result.

helper.java

This file contains the methods evaluate, hasPrecedence, and applyOp.

evaluate(String input)

The evaluate method takes a string input and evaluates it as a mathematical expression using the Shunting Yard algorithm. It uses two stacks, one for operands and one for operators. The method converts the input string from infix notation to postfix notation and then evaluates it.

hasPrecedence(char op1, char op2)

The hasPrecedence method compares the precedence of two operators, op1 and op2. It returns true if op1 has higher or equal precedence than op2, and false otherwise. This method is used in the evaluate method to ensure that the operators are applied in the correct order.

applyOp(char op, double b, double a)

The applyOp method takes an operator, op, and two operands, a and b, and applies the operator to the operands. It returns the result of the operation. This method is used in the evaluate method to apply the operators to the operands.

How to Run

  1. Clone the repository git clone https://github.com/OpenGenus/calculator-in-java.git
  2. Open the project in your preferred IDE
  3. Compile and run the main.java file
  4. Input the mathematical expression you want to evaluate
  5. The result will be displayed on the console

Note: The calculator only supports basic arithmetic operations such as addition, subtraction, multiplication, and division. It also supports the use of parentheses.

For the full explanation of the project, visit the link.

calculator-in-java's People

Contributors

abhijeetsaroha avatar adichat avatar

Watchers

 avatar  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.