Skip to content

Developer-Sahil/scientific-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scientific Calculator

A feature-rich scientific calculator built with Java and JavaFX, featuring a modern dark theme and comprehensive mathematical operations.

Calculator Screenshot

Features

Basic Operations

  • Addition, Subtraction, Multiplication, Division
  • Decimal point support
  • Sign change (+/-)
  • Power operations (x^y)

Scientific Functions

  • Trigonometric: sin, cos, tan, asin, acos, atan
  • Logarithmic: Natural logarithm (ln), Common logarithm (log)
  • Exponential: e^x
  • Other: Square root (√), Square (x²), Reciprocal (1/x), Factorial (x!)

Constants

  • π (Pi): 3.14159...
  • e (Euler's number): 2.71828...

Additional Features

  • Angle Mode Toggle: Switch between Radians and Degrees
  • Clear Functions:
    • C (Clear all)
    • CE (Clear entry)
    • Backspace
  • Error Handling: Graceful handling of division by zero and invalid operations
  • Minimalistic UI: Dark theme with color-coded buttons for easy navigation

Requirements

  • Java Development Kit (JDK): Version 17 or higher
  • JavaFX SDK: Version 17 or higher (must match your Java version)

Java & JavaFX Version Compatibility

Java Version Compatible JavaFX Version
Java 11-17 JavaFX 17
Java 18-20 JavaFX 20
Java 21+ JavaFX 21+

Installation

Prerequisites

  1. Install Java JDK

  2. Download JavaFX SDK

    • Download from: Gluon JavaFX
    • Extract to a location (e.g., C:\javafx-sdk-17)

Project Setup

Clone or download this repository:

git clone https://github.com/yourusername/scientific-calculator.git
cd scientific-calculator

Running the Application

Refer to your IDE or build tool documentation for running JavaFX applications with the appropriate module path configuration.

Project Structure

scientific-calculator/
├── README.md
└── ScientificCalculator.java    # Main application file

Usage Guide

Basic Calculations

  1. Enter numbers using the number pad (0-9)
  2. Click an operator (+, -, *, /)
  3. Enter the second number
  4. Press = to see the result

Scientific Functions

  1. Enter a number
  2. Click the desired function (sin, cos, log, etc.)
  3. The result is displayed immediately

Using Constants

  • Click π to insert Pi value
  • Click e to insert Euler's number

Angle Mode

  • Click Rad to toggle between Radians and Degrees mode
  • Affects trigonometric functions (sin, cos, tan)

Special Operations

  • x^y: Enter base number, click x^y, enter exponent, press =
  • x!: Enter a non-negative integer, click x!
  • +/-: Change the sign of the current number
  • 1/x: Calculate reciprocal of current number

Button Reference

Button Function
0-9 Number input
. Decimal point
+, -, *, / Basic arithmetic operators
= Calculate result
C Clear all (reset calculator)
CE Clear current entry
< Backspace (delete last digit)
sin, cos, tan Trigonometric functions
asin, acos, atan Inverse trigonometric functions
ln Natural logarithm
log Common logarithm (base 10)
sqrt Square root
x^2 Square
x^y Power
1/x Reciprocal
x! Factorial
exp Exponential (e^x)
π Pi constant
e Euler's number
+/- Change sign
Rad/Deg Toggle angle mode

Troubleshooting

"Module not found: javafx.controls"

  • Cause: JavaFX is not installed or not in the module path
  • Solution: Download JavaFX SDK and specify the correct path with --module-path

"class file has wrong version" Error

  • Cause: JavaFX version doesn't match your Java version
  • Solution: Download compatible JavaFX version (see compatibility table above)

"Cannot find java command"

  • Cause: Java is not installed or not in PATH
  • Solution: Install JDK and add to system PATH

Calculator window doesn't appear

  • Cause: JavaFX runtime modules not loaded
  • Solution: Ensure --add-modules javafx.controls is specified when running

Error on button click

  • Cause: Invalid input or operation
  • Solution: Click C to clear and try again

Building from Source

Compile the source code:

javac --module-path /path/to/javafx-sdk/lib --add-modules javafx.controls ScientificCalculator.java

Run the application:

java --module-path /path/to/javafx-sdk/lib --add-modules javafx.controls ScientificCalculator

Windows Example:

javac --module-path "C:\javafx-sdk-17\lib" --add-modules javafx.controls ScientificCalculator.java
java --module-path "C:\javafx-sdk-17\lib" --add-modules javafx.controls ScientificCalculator

Linux/Mac Example:

javac --module-path /opt/javafx-sdk-17/lib --add-modules javafx.controls ScientificCalculator.java
java --module-path /opt/javafx-sdk-17/lib --add-modules javafx.controls ScientificCalculator

IDE Setup

IntelliJ IDEA

  1. Open project in IntelliJ
  2. File → Project Structure → Libraries
  3. Add JavaFX SDK library
  4. Run → Edit Configurations
  5. Add VM options: --module-path /path/to/javafx-sdk/lib --add-modules javafx.controls

Eclipse

  1. Open project in Eclipse
  2. Right-click project → Properties → Java Build Path
  3. Add External JARs from JavaFX SDK lib folder
  4. Run → Run Configurations
  5. Add VM arguments: --module-path /path/to/javafx-sdk/lib --add-modules javafx.controls

VS Code

  1. Install Java Extension Pack
  2. Create .vscode/launch.json:
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "ScientificCalculator",
            "request": "launch",
            "mainClass": "ScientificCalculator",
            "vmArgs": "--module-path /path/to/javafx-sdk/lib --add-modules javafx.controls"
        }
    ]
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Future Enhancements

  • Memory functions (M+, M-, MR, MC)
  • Scientific notation input
  • Parentheses support for complex expressions
  • History of calculations
  • Keyboard input support
  • Theme customization
  • Export/save results
  • Unit conversions

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Your Name - Sahil Sharma

Project Link: https://github.com/Developer-Sahil/scientific-calculator

Acknowledgments

  • Built with JavaFX
  • Inspired by modern calculator designs
  • Special thanks to the Java community

Note: This calculator is designed for educational purposes and basic scientific calculations. For advanced mathematical operations, consider using specialized software like MATLAB, Mathematica, or SciPy.

About

A feature-rich scientific calculator built with Java and JavaFX, featuring a modern dark theme and comprehensive mathematical operations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages