Skip to content

A simple command-line calculator that performs basic arithmetic operations like addition, subtraction, multiplication, and division.

Notifications You must be signed in to change notification settings

Sumermal/Java-Console-Calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Java Console Calculator

Java License Platform

A Java Console-based Calculator with multiple operations, error handling, and history tracking.
Perfect for learning Java basics, loops, methods, exception handling, and console input/output.


✨ Features

Operation Description
βž• Addition Adds two numbers
βž– Subtraction Subtracts second number from first
βœ–οΈ Multiplication Multiplies two numbers
βž— Division Divides first number by second (handles divide by zero)
% Modulus Calculates remainder
x^y Power Calculates first number raised to second number
√ Square Root Calculates square root (handles negative numbers)
n! Factorial Calculates factorial of an integer (non-negative)
πŸ“œ History Keeps a log of all previous operations

πŸ–₯️ How to Run

  1. Clone the Repository:

     First, download the project from GitHub:
     git clone https://github.com/Sumermal/Java-Console-Calculator.git
    
     This will create a folder your-repo-name containing the project files.
    
  2. Open in an IDE:

     Open IntelliJ IDEA (or any Java IDE).
    
     Choose Open β†’ Select the project folder you cloned.
    
     Make sure ConsoleCalculator.java is inside the src/ directory.
    
  3. Compile and Run:

     Run in IntelliJ :
    
     Right-click ConsoleCalculator.java β†’ Run 'ConsoleCalculator.main()'
    
     The program will open in the console, displaying the menu.
    
  4. Using the Calculator

The program will show a menu with operations:

    1. Addition (+)
    2. Subtraction (-)
    3. Multiplication (*)
    4. Division (/)
    5. Modulus (%)
    6. Power (x^y)
    7. Square Root (√x)
    8. Factorial (n!)
    9. Show History
    10. Exit


    Enter the number of the operation, then input your numbers.

    Results will display immediately.

    Option 9 shows the history of all calculations.

    Option 10 exits the calculator.
  1. Notes:

     Division by zero β†’ returns NaN.
    
    Square root of negative numbers β†’ returns NaN.
    
     Factorial only supports non-negative integers.
    

πŸ› οΈ Tech Stack

Java 8+

Console input/output

ArrayList for history

πŸ“ Project Structure

ConsoleCalculator/
β”œβ”€ src/
β”‚  └─ ConsoleCalculator.java
β”œβ”€ .gitignore
β”œβ”€ README.md

πŸ‘¨β€πŸ’» Author

Lohar Sumermal
Java Developer | Backend Enthusiast

About

A simple command-line calculator that performs basic arithmetic operations like addition, subtraction, multiplication, and division.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages