Skip to content

ThatoMabilo/java-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Console Calculator

A console-based calculator application built in Java.


Project Description

This project implements a feature-rich console-based calculator using Java. It demonstrates:

  • Object-Oriented Programming (OOP) principles
  • Clean code structure with separation of concerns
  • Meaningful Git commit history and version control practices

The calculator supports arithmetic operations, keeps a session history, and provides a clean, color-coded terminal interface.

Note: All the results are displayed to 4 decimal places for consistency (e.g. 120 displays as 120.0000). This makes sure that there is uniform formatting across both whole numbers and decimal results.


Features

Feature Description
➕ Addition Add two numbers
➖ Subtraction Subtract one number from another
✖️ Multiplication Multiply two numbers
➗ Division Divide with zero-division error handling
% Modulus Find the remainder of division
^ Power Raise a number to an exponent
√ Square Root Compute the square root (with negative guard)
History View all calculations made in the current session
Clear Reset history and last result

Project Structure

java-calculator/
├── src/
│   └── calculator/
│       ├── Main.java           # Entry point & CLI interface
│       └── Calculator.java     # Core arithmetic logic
├── .gitignore
└── README.md

⚙️ Prerequisites

Requirement Version
Java JDK 17+

How to Run

1. Clone the Repository

git clone https://github.com/ThatoMabilo/java-calculator.git
cd java-calculator

2. Compile the Source Files

javac -d out src/calculator/Main.java src/calculator/Calculator.java

3. Run the Application

java -cp out calculator.Main

4. Using the Calculator

Once launched, you'll see a menu like this:

  ── Operations ─────────────────────────
  1  Addition          (+)
  2  Subtraction        (-)
  3  Multiplication     (*)
  4  Division           (/)
  5  Modulus            (%)
  6  Power              (^)
  7  Square Root        (√)
  ── Utilities ────────────────────────────
  8  Show Last Result
  9  Show History
  0  Clear History
  q  Quit

Enter the number of the operation you want, then enter your numbers when prompted.


Screenshots

Screenshots of the application running on my local machine are available in the /screenshots folder of this repository.


Example Session

  Enter choice: 1
  Enter first number : 15.5
  Enter second number: 4.5

  15.5000  +  4.5000  =  20.0000

  Enter choice: 6
  Enter first number : 2
  Enter second number: 10

  2.0000  ^  10.0000  =  1024.0000

  Enter choice: 9

  ── Calculation History ──
  15.0000 + 4.5000 = 20.0000
  2.0000 ^ 10.0000 = 1024.0000

Git Commit History

This project follows a structured commit strategy:

Commit Description
init Initial project scaffold and README
feat Add Calculator core logic (all operations)
feat Add Main CLI with color-coded menu
fix Handle edge cases (div by zero, negative sqrt)
docs Update README with usage instructions

Author

  • Student: Thato Anikie Mabilo
  • Student Number: 222148349
  • Lecturer: Dr. Boniface Kabaso
  • Program: Console-based Calculator

About

A console-based calculator application built in Java

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages