Package com.project.calculator
Class Logic
java.lang.Object
com.project.calculator.Logic
The
Logic
class handles the core operations and event handling for the calculator.
It performs the following tasks:
- Processes button click events.
- Handles mathematical operations and displays the result.
- Manages clearing the display and maintaining history.
This class interacts with both the BaseUI
and MainUI
to
display the results and maintain the input history.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Handles the evaluation of the expression and displays the result.protected void
performAction
(ActionEvent keyPressed) Handles the button press events and performs the appropriate action based on the input.
-
Field Details
-
baseUiInstance
Reference to theBaseUI
instance for accessing display and history labels. -
mainUiInstance
Reference to theMainUI
instance for handling input and result operations.
-
-
Constructor Details
-
Logic
Constructs theLogic
object with references to the UI instances.- Parameters:
baseUiInstance
- TheBaseUI
instance for display and history management.mainUiInstance
- TheMainUI
instance for input and button handling.
-
-
Method Details
-
performAction
Handles the button press events and performs the appropriate action based on the input.It processes digits, operators, clear operations, and evaluates expressions.
- Parameters:
keyPressed
- TheActionEvent
triggered by the button press.
-
handleResult
private void handleResult()Handles the evaluation of the expression and displays the result.This method:
- Converts the infix expression to postfix using
InfixToPostfix
class. - Evaluates the result and displays it.
- Updates the input and history.
- Converts the infix expression to postfix using
-