You are on page 1of 14

A PROJECT REPORT ON

CALCULATOR
Submitted in partial fulfillment of the requirements for

the award of the degree of

BACHELOR OF TECHNOLOGY
In

COMPUTER SCIENCE AND ENGINEERING

Submitted by

D.AJAY – (22841A05E6)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

AURORA’S TECHNOLOGICAL AND RESEARCH INSTITUTE


(Approved by AICTE and Affiliated to JNTUH) (Accredited by NAAC with ‘A’ Grade)
Parvathapur, Uppal, Hyderabad-500098

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

Assistant Professor, ATRI

Head of the Department PRINCIPAL

Dr. Durga Pavani Dr.A.Mahesh Babu


(Department of CSE)
ACKNOWLEDGEMENT

I would like to express my gratitude to Mrs. Madhavi, A Project Guide, Assistant


Professor, ATRI for her guidance, valuable suggestions and encouragement in completing
the Technical Seminar work within the stipulated time.

I would like to express my immense gratitude to Mrs.Durga Pavani, Head of the


Department CSE, ATRI, Associate Professor for her guidance, valuable suggestions and
encouragement in completing the Technical Seminar work within the stipulated time.

I would like to express my sincere thanks to Dr.A.Mahesh Babu, Principal, Aurora's


Technological and Research Institute, Parvathapur, Hyderabad-500098 for permitting me
to do my Technical Seminar work.

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

3 PROGRAM ALOGRITHIM 4-6

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:

1. *Graphical User Interface (GUI):*


- The calculator employs Java's Swing framework to create a graphical interface.
- Components such as buttons, labels, and text fields are utilized to enhance user interaction.

2. *User Input Handling:*


- The program captures user input through button clicks on the GUI.
- The input, typically numeric values or mathematical operators, is processed to perform calculations.

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.

6. *Clearing and Resetting:*


- Buttons for clearing the input or resetting the calculator provide users with control and ease of use.

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;

public class Calculator {

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

System.out.println("Java Calculator");
System.out.println("Enter two numbers:");

double num1 = scanner.nextDouble();


double num2 = scanner.nextDouble();

System.out.println("Select operation: +, -, *, /");


char operation = scanner.next().charAt(0);

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);
}

System.out.println("Result: " + result);


}
}

11
OUTPUT

Java Calculator

Enter two numbers:

Select operation: +, -, *, /

Result: 8.0

12
SUMMARY

The Java calculator program is a console-based application designed to perform basic


arithmetic operations. It begins by prompting the user to input two numbers, then asks for
the desired operation (+, -, *, /). The program utilizes a switch statement to execute the
chosen operation, handling division by zero and invalid operations. The result is
calculated and displayed on the console. The program serves as a foundational example
for learning Java, showcasing user input handling, conditional statements, and basic
arithmetic operations. For enhanced usability, this basic console calculator could be
extended to include a graphical user interface using Java Swing or JavaFX.

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

You might also like