How sapoclay/calculaydora-cientrifica works
Project Type and Purpose
• This is a standalone desktop application implemented in Java (version 17+) using Swing for its GUI.
• Purpose: A scientific calculator that supports basic arithmetic, advanced functions (trigonometry, powers, square roots), and uses the Shunting-yard algorithm for expression evaluation.
High-Level Architectural Pattern
• We’ll map it to an MVC-inspired, layered monolith:
• View: Swing GUI components
• Controller: Event listeners / input handlers
• Model: Expression engine (tokenizer, parser, evaluator)
• Utility modules: error handler, history tracker (in-memory)
Main Components
a. GUI Layer (View)
• JFrame / JPanel with GridBagLayout
• Buttons, display field, history panel
• Tooltips, keyboard listeners
b. Input Controller
• ActionListeners and KeyListeners that capture button presses / keystrokes
• Build an infix expression string
c. Tokenizer
• Scans the infix string into tokens: numbers, operators, parentheses, functions
d. Parser / Shunting-yard Engine
• Converts infix tokens → postfix queue
• Manages operator precedence & associativity
e. Evaluator
• Uses a stack to compute the postfix expression
• Implements function calls (sin, cos, sqrt, etc.)
f. Error Handling Module
• Validates parentheses balance, division by zero, malformed input
• Populates GUI error dialogs or messages
g. In-Memory History Tracker
• Stores last N expressions & results for display (optional)
Relationships & Data Flows
1. User → (click/keypress) → GUI Layer
2. GUI Layer → Input Controller → Expression String
3. Controller → Tokenizer → Token List
4. Token List → Shunting-yard Parser → Postfix Queue
5. Postfix Queue → Evaluator → Numeric Result or Error
6. Result → GUI Layer (update display & history)
Architectural Patterns & Design Principles
• Layering: GUI | Controller | Model
• Single Responsibility: each module (tokenizer, parser, evaluator) has a clear role
• In-memory state: no external DB, state lives in application memory
• Algorithmic core: Shunting-yard for conversion + stack-based evaluation
Key Technologies & Frameworks
• Java 17+
• Swing (javax.swing) for desktop UI
• Java Collections (Stack, List, Queue)
• Maven for build (pom.xml implied in README)