C4LCUL4TOR is a simple, hacker-styled calculator application developed in Java using Swing for the graphical user interface.
- Basic arithmetic operations: addition, subtraction, multiplication, division
- Additional operations: exponentiation, modulo
- Retro/hacker-style green-on-black interface
- Error handling for syntax errors and division by zero
- I wonder what displays after inputting
69696969...?
- Java Development Kit (JDK) 8 or higher
-
Clone/download this repo then run
Main -
Download only the
calculator_app.jarfile and run this at the jar's directory:java -jar calculator_app.jar
The following coding conventions were used in the development of this application:
-
Naming Conventions:
- Classes: PascalCase (e.g.,
Screen,Main) - Methods and variables: camelCase (e.g.,
createDisplay(),firstOperand) - Constants: UPPER_SNAKE_CASE (e.g.,
WINDOW_WIDTH,BG_COLOR)
- Classes: PascalCase (e.g.,
-
Package Structure:
- All classes are in the
com.calcuapppackage
- All classes are in the
-
Access Modifiers:
- Classes are declared as
public - The
Screenclass is declared asfinalto prevent inheritance - Fields are generally
privateunless needed otherwise - Constants are declared as
private static final
- Classes are declared as
-
Code Organization:
- Related methods are grouped together (e.g., UI creation methods, calculation methods)
- Constants are declared at the top of the class
-
Comments:
- Single-line comments are used for brief explanations
- Method-level comments are omitted in favor of self-explanatory method names
-
Error Handling:
- Try-catch blocks are used for potential exceptions (e.g.,
NumberFormatException) - Custom error messages are displayed for syntax errors and division by zero
- Try-catch blocks are used for potential exceptions (e.g.,
-
UI Design:
- Consistent color scheme using predefined color constants
- Uniform sizing and spacing of UI elements
-
Event Handling:
- Lambda expressions are used for ActionListeners
-
Data Types:
- Appropriate primitive types are used (e.g.,
doublefor operands,charfor operators)
- Appropriate primitive types are used (e.g.,
-
Method Design:
- Methods are kept short and focused on a single responsibility
- Private helper methods are used to break down complex operations
-
Constants:
- Magic numbers and strings are avoided in favor of named constants
-
Serialization:
serialVersionUIDis defined for theScreenclass which extendsJFrame
-
Null Handling:
- Null checks are implicit through the use of the Swing framework
-
Resource Management:
- Swing components are used, which handle resource management automatically
-
Formatting:
- Consistent indentation (4 spaces)
- Braces on the same line as control statements
- Spaces around operators and after commas
These conventions contribute to the readability, maintainability, and consistency of the codebase.