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 voidHandles the evaluation of the expression and displays the result.protected voidperformAction(ActionEvent keyPressed) Handles the button press events and performs the appropriate action based on the input.
-
Field Details
-
baseUiInstance
Reference to theBaseUIinstance for accessing display and history labels. -
mainUiInstance
Reference to theMainUIinstance for handling input and result operations.
-
-
Constructor Details
-
Logic
Constructs theLogicobject with references to the UI instances.- Parameters:
baseUiInstance- TheBaseUIinstance for display and history management.mainUiInstance- TheMainUIinstance 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- TheActionEventtriggered 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
InfixToPostfixclass. - Evaluates the result and displays it.
- Updates the input and history.
- Converts the infix expression to postfix using
-