Your project is well-structured and shows a good understanding of shunting yard algorithm with usage of tokenization, parsing, and evaluation. Code has been separated in a reasonable way into different classes. Basic funcitonality of the calculator seems to be working well. Unittesting has also been started.
Here are few of my suggestions for improvement.
Suggestions:
Tokenizer Class:
Usage of charAt(): Consider using charAt() instead of substring(). Using substring() creates unnecessary new string objects and increases memory usage especially in large expressions or loops
Error Handling: At the moment using an unregocnized symbol, for example 2^3 gives an infinite loop with message Error! character was not recognised: ^.
Exceptions/Error messages: Instead of printing errors with System.out.println , use IllegalArgumentException to throw exceptions
Evaluator Class:
Division by Zero: Add specific error handling for division by zero for more informative feedback to the user.
CalculatorUI:
User Feedback: Improve error messages for invalid expressions with more informative feedback (e.g., "Unrecognized character" or "Mismatched parentheses").
Unit Testing:
Edge Cases: It could be necessary to add more edge case tests such as
testing with: very large and very small numbers, complex nested parentheses, divided by zero, etc.
General Structure:
JavaDoc comments: Even though some parts of the code are already commented, consider using more precise JavaDoc comments to methods and classes as recommended in course material. It would make the code easier/faster to explore (especially for someone who hasn't worked with Java in a while, like myself )
Overall:
Algorithm is understood, program is working, the code is well-organized and easy to follow. Keep up the good work!
Peer Review
Project downloaded: 1.10 at 12.00
General Feedback:
Your project is well-structured and shows a good understanding of shunting yard algorithm with usage of tokenization, parsing, and evaluation. Code has been separated in a reasonable way into different classes. Basic funcitonality of the calculator seems to be working well. Unittesting has also been started.
Here are few of my suggestions for improvement.
Suggestions:
Tokenizer Class:
charAt()
instead ofsubstring()
. Usingsubstring()
creates unnecessary new string objects and increases memory usage especially in large expressions or loops2^3
gives an infinite loop with messageError! character was not recognised: ^
.System.out.println
, useIllegalArgumentException
to throw exceptionsEvaluator Class:
CalculatorUI:
Unit Testing:
General Structure:
Overall:
Algorithm is understood, program is working, the code is well-organized and easy to follow. Keep up the good work!