Skip to content

Optymist/java_calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Swing Calculator

A simple, interactive calculator built using Java Swing. This calculator application allows users to perform basic arithmetic operations (following BODMAS rules) and includes an interactive GUI interface with buttons and a display area. Users can enter calculations using both mouse clicks on the buttons and keyboard input (including pressing Enter for quick calculation).

Features

  • Basic Arithmetic Operations: Supports addition, subtraction, multiplication, division, power and squareroot funcionality.
  • Keyboard Input: Press Enter for calculation, as well as using +, -, *, and / keys.
  • Undo Button: Delete the last character of the input, or navigate in the textfield to where you want to delete and delete the character before your caret position.
  • Color Customization: Choose a background color for the calculator.
  • Error Handling: Displays friendly error messages for invalid operations, such as division by zero.

Getting Started

These instructions will help you set up and run the Java Swing Calculator on your local machine.

Prerequisites

Make sure you have the following installed:

  • Java Development Kit (JDK): Version 11 or later. You can download it from Oracle's website or OpenJDK.
  • Git: To clone the repository. If you don’t have Git, download it from Git’s website.
  • An IDE or Text Editor (Optional but recommended): An IDE like IntelliJ IDEA or Eclipse can make it easier to run and test the project.

Running the Calculator

  1. Clone the repository:
    git clone https://github.com/Optymist/java_calculator.git
    

Option 1 (standard file navigation)

  1. Open the project in your preferred IDE.
  2. Locate the Calculator.java file.
  3. Right click and run or press the ▶ button next to the class name.

Option 2 (running from the command line)

  1. Ensure you are in the project directory:
    cd ~/java_calculator/calculator
  2. Compile the program:
    javac -d bin src/main/java/org/example/Calculator.java
  3. Run the program:
    java -cp bin org.example.Calculator
    
    
  4. After executing any of these, a window should pop up with the calculator's screen evident.

Testing the Calculator

Option 1 (standard file navigation)

  1. Locate the test/java package.
  2. Right click and run the tests.

Option 2 (from the command line)

  1. Navigate to the repository:
    cd ~/java_calculator/calculator
  2. Run the tests using Maven:
    mvn test
    
    
  3. After executing any of these, the tests should run and should all pass successfully.

Future Enhancements

I plan to add more advanced features in future versions, including:

  • Advanced Functions: Adding support for square roots, trigonometric functions, radians, pi, and more advanced calculation functionality.
  • Memory Functions: Include options to store and recall memory values.
  • Calculation History: Show previous calculations, allowing users to reference or reuse past results.
  • Error Logging: Add a log for errors and warnings that users encounter while using the calculator.

Tech Stack

The project is built with:

  • Java: Core programming language for the application.
  • Java Swing: Used for creating the graphical user interface (GUI).
  • JUnit: For unit testing and GUI testing.

Optional:

  • Maven or Gradle (if used for managing dependencies or building the project).

Contributing

This is a personal project that I have implemented for my own growth but if you would like to contribute you can email me at kimlynsmart@gmail.com.

About

Calculator with gui written in Java using JavaSwing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages