Java - Project AJ
Java - Project AJ
CALCULATOR
Submitted in partial fulfillment of the requirements for
BACHELOR OF TECHNOLOGY
In
Submitted by
D.AJAY – (22841A05E6)
JANUARY 2024
CERTIFICATE
This is to certify that the project report entitled “CALCULATOR” has been submitted by,
D.AJAY(22841A05E6) in partial fulfillment for laboratory project in of Programming for Problem
through object oriented programming through java Laboratory is a record of bona fide work carried
out by them under my guidance and supervision.
Date:
Hyderabad
GUIDE
Mrs.Madhavi
Finally, I would also like to thank the people who have directly or indirectly helped me, my
parents and my friends for their cooperation in completing the project.
ABSTRACT
This Java-based calculator program aims to provide a user-friendly and efficient tool for
performing basic arithmetic operations. The calculator is designed using Java programming
language, incorporating fundamental concepts such as user input handling, mathematical
operations, and graphical user interface (GUI) components. Utilizing Swing for the GUI, the
program offers a simple and intuitive interface with buttons for addition, subtraction,
multiplication, and division. Additionally, it includes functionality for clearing the input,
handling decimal numbers, and displaying results dynamically. The implementation leverages
object-oriented principles to enhance modularity and maintainability. This calculator serves as a
practical example for beginners learning Java programming and GUI development.
INDEX
CONTENTS PAGE
NO
1 INTRODUCTION 1
2 EXPLAINTION 2-3
4 OUTPUT 7-8
5 SUMMARY 9
6 CONCLUSION 10
Introduction
The Java Calculator program is a simple yet effective application designed to perform basic
arithmetic operations through a user-friendly graphical interface. Developed using Java
programming language, this calculator demonstrates essential concepts in Java, such as event
handling, GUI design, and object-oriented programming.
The calculator utilizes the Swing framework for creating a responsive graphical user
interface. Users can interact with the calculator using a set of buttons representing numbers,
mathematical operators, and additional functionalities. The program supports standard
arithmetic operations like addition, subtraction, multiplication, and division, providing a
versatile tool for performing calculations.
Through this project, developers can gain hands-on experience in Java programming and GUI
development. The use of object-oriented principles enhances the code's structure, making it
more modular and maintainable. This calculator serves as an instructive example for those
learning Java, offering insights into handling user input, managing events, and creating an
interactive application. Whether for educational purposes or practical use, this Java Calculator
program demonstrates the power of Java in creating functional and user-friendly applications.
7
Explanation
The Java Calculator program is built to facilitate basic arithmetic calculations through a user-friendly
interface. Below are key aspects explaining its functionality:
3. *Arithmetic Operations:*
- The calculator supports standard arithmetic operations: addition, subtraction, multiplication, and
division.
- When a mathematical operation button is pressed, the program evaluates the expression based on
the current input.
4. *Error Handling:*
- The calculator is designed to handle errors gracefully, preventing unexpected behaviors or crashes.
- Common scenarios, such as division by zero or invalid input, are addressed to ensure a robust user
experience.
5. *Dynamic Display:*
- The program dynamically updates the display to show the input and results as users interact with
the calculator.
- This real-time feedback enhances the user experience and aids in understanding the ongoing
calculation.
7. *Object-Oriented Design:*
- The calculator is structured using object-oriented principles to enhance modularity and
maintainability.
- Classes and methods are organized logically, promoting code readability and scalability.
8. *Decimal Handling:*
- The calculator accommodates decimal numbers, allowing users to perform calculations with
precision.
8
By combining these elements, the Java Calculator program delivers a functional and educational tool
for individuals learning Java programming. It showcases practical application of GUI development,
event handling, and object-oriented programming principles in a context familiar to users.
9
PROGRAM ALOGRITHIM
import java.util.Scanner;
System.out.println("Java Calculator");
System.out.println("Enter two numbers:");
double result = 0;
switch (operation) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
10
} else {
System.out.println("Error: Division by zero");
System.exit(0);
}
break;
default:
System.out.println("Error: Invalid operation");
System.exit(0);
}
11
OUTPUT
Java Calculator
Select operation: +, -, *, /
Result: 8.0
12
SUMMARY
13
CONCLUSION
In conclusion, the Java Calculator program presented here serves as a fundamental illustration of
core programming concepts, including user input handling, graphical user interface design using
Swing, and basic arithmetic operations. The application provides a practical example for
beginners learning Java, showcasing the implementation of object-oriented principles for code
organization and modularity.
Through this calculator project, developers can gain insights into creating interactive
applications, managing user input, and handling errors gracefully. The inclusion of features such
as dynamic display, error handling, and support for decimal numbers enhances the program's
usability and user experience.
While this calculator program is console-based for simplicity, it lays the foundation for further
enhancements, such as transitioning to a graphical user interface (GUI) using frameworks like
Swing or JavaFX. This extension would offer users a more intuitive and visually appealing
interface, making the calculator a versatile tool for both learning and practical use.
Overall, the Java Calculator program exemplifies the power of Java in building functional and
user-friendly applications, making it a valuable resource for individuals seeking to expand their
programming skills.
14