Skip to content

happyjung23/java-scientific-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

java-scientific-calculator

A Java calculator with standard operations

Java Scientific Calculator (Swing)

A desktop calculator built with Java Swing (NetBeans GUI) that supports standard arithmetic plus a few scientific functions, with smart output formatting and guardrails.

Calculator UI


Features

  • Arithmetic: +, , ×, ÷
  • Scientific:
    • (square)
    • √x (square root)
    • π×x (multiply current value by π)
  • Input & Display UX:
    • Sign toggle +/−
    • Decimal guard (prevents multiple .)
    • Backspace <, C (clear entry), AC (full reset)
    • Output formatting:
      • Trims trailing .0 (e.g., 12.0 → 12)
      • Caps display length to 10 characters while preserving scientific notation (e.g., 1.23E9)
  • Chaining: Pressing an operator stores the current number; selecting another operator applies the previous one (sequential evaluation).
  • Polish: Prevents editing a finalized answer until new input; friendly warnings; a tiny easter egg button (“Don’t Push”).

How It Works

  • Main class: finalproject.FormB (JFrame with right-aligned JTextField display and button grid)
  • State variables:
    • input1, input2, outcome
    • Operation flags: mul, div, add, sub
    • ansDisplay (locks display after =), limit (max input length), curOP (op sequence counter)
  • Core methods:
    • operate() — executes + / − / × / ÷ on input1 and input2
    • extraOP(int) — applies , √x, π×x immediately to current display
    • cutzero() & cutLimit() — trims trailing .0 and enforces 10-char display, respecting scientific notation
    • typeNumber(String) / delete() — controlled input & backspace behavior

Operator precedence is sequential (in the order you press buttons), not algebraic precedence.


About

A Java calculator with standard operations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages