Calculator using Java
By Pranav Bhargava
This is a complex scientific calculator made using Java and Java awt. It can perform scientific trignometric functions along with simple arithmetic .
README file:
Simple Java Calculator
This project is a simple Java calculator application that provides basic arithmetic and scientific calculations through a user-friendly graphical interface. It supports binary operations (two operands) and unary operations (one operand), making it suitable for both simple and advanced mathematical calculations.
Features:
- Basic Arithmetic Operations: Addition, Subtraction, Multiplication, Division
- Scientific Functions: Square, Square Root, Reciprocal, Cosine, Sine, Tangent, Logarithm, Natural Logarithm, Percentage, Absolute Value, Power of Y (X^Y)
- Binary and Unary Operations: Perform calculations with two or one operands, respectively.
- Clear Functionality: Reset the calculator to its initial state.
- Graphical User Interface: The calculator includes a user-friendly GUI with buttons for easy interaction.
How to Run:
-
Import the Project into Eclipse:
- Open Eclipse IDE and select "File" > "Open Projects from File System."
- Click on "Directory" and navigate to the folder containing the project.
- Click "Finish" to import the project into Eclipse.
-
Set Up Build Path:
- Right-click on the project in the Project Explorer pane.
- Select "Build Path" > "Configure Build Path."
- In the "Libraries" tab, ensure that the JRE System Library is correctly configured.
-
Run the Program:
- Open the
SimpleJavaCalculator
class located in the package simplejavacalculator
.
- Right-click within the class code area and select "Run As" > "Java Application."
Usage:
- The calculator window will open, displaying the numeric keypad and various mathematical functions.
- Click the numeric buttons (0-9) to enter digits.
- Click the arithmetic buttons (+, -, *, /) to perform binary operations with two operands.
- Click the scientific function buttons (e.g., "sqrt," "sin," "cos," etc.) to perform unary operations with one operand.
- Use the "C" button to reset the calculator.
- To calculate the result, click the "=" button.
- The result will be displayed in the text area at the top of the calculator window.
- For binary operations, enter the first operand, click the desired arithmetic operation, enter the second operand, and then click "=" to get the result.
- The calculator also supports percentage calculations; click the "x%" button after entering the value.
Testing:
The project includes a CalculatorTest
class with JUnit test cases to verify the correctness of the calculator's operations. To run the tests, right-click on the CalculatorTest
class in the Package Explorer, and select "Run As" > "JUnit Test."
Platform:
This Java calculator application is designed to run on any platform that supports Java, including Windows, macOS, and Linux. It has been developed and tested in Eclipse IDE using JDK (Java Development Kit).




Comments