This Java application provides a command-line calculator with basic functionalities. It supports operations such as addition, subtraction, multiplication, division, and exponentiation. The main purpose was to implement following design patterns:
- Builder pattern
- Chain of responsibility pattern
- Memento pattern
Is used to create Calculator. Two types of calculators available(can be found further) dependant on mood and operations list.
Sequentially performs operations on input numbers if operator matches.
Simply rolls back to previously obtained results. Main class works as Caretaker here.
- Java Development Kit (JDK) installed
- Open a terminal or command prompt.
- Navigate to the directory containing the compiled Java classes.
- Run the application using the following command:
Replace <calculator_type> with either "simple" for the basic calculator or "eng" for the engineering calculator. <starting_number> should be the initial numeric value for calculations.
java Main <calculator_type> <starting_number>
This will start the simple calculator with an initial value of 0.java Main simple 0
The simple calculator performs basic arithmetic operations, including addition, subtraction, multiplication, division.
The engineering calculator extends the functionality of the simple calculator to include exponentiation, also excludes addition and substraction.
- Input operation: Enter one of the following operators - "+", "-", "*", "/", "^" (exponentiation).
- Rollback: Type "rollback" to undo the last operation and revert to the previous result.
The application provides error handling for various scenarios:
- Incorrect number of command-line arguments.
- Invalid calculator type.
- Invalid input during calculator operations.
- Unsupported or incorrect operators.
- Rollback attempts when no operations have been performed.
- Rollback: The application allows the user to undo the last operation and revert to the previous result by typing "rollback."
- Mood Feedback: The calculator expresses its mood based on the user's interactions, providing humorous feedback in case of errors or unconventional inputs.
- The application uses a stack-based mechanism to save and restore calculator states for rollback functionality.
- A maximum of 50 states are retained in the rollback history.
- The application provides feedback messages based on the mood of the calculator. Feel free to explore and enjoy using the command-line calculator!