0% found this document useful (0 votes)
21 views12 pages

Java Calculator Applet Design Report

This document describes a micro project to design a calculator applet using Java. A group of 3 students - Pinil Baburav Chakar, Rohit Rajendra Sonawane, and Suraj Gurunath Raut - completed the project under the guidance of their professor. The project involved creating a calculator applet that can perform basic mathematical operations like addition, subtraction, multiplication, and division on user input values and display the output. The source code for the calculator applet is included, which uses buttons, text fields, panels, and action listeners to accept user input, perform calculations, and display results. Certificates are also provided to certify that the students satisfactorily completed the micro project.

Uploaded by

chakarpinil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views12 pages

Java Calculator Applet Design Report

This document describes a micro project to design a calculator applet using Java. A group of 3 students - Pinil Baburav Chakar, Rohit Rajendra Sonawane, and Suraj Gurunath Raut - completed the project under the guidance of their professor. The project involved creating a calculator applet that can perform basic mathematical operations like addition, subtraction, multiplication, and division on user input values and display the output. The source code for the calculator applet is included, which uses buttons, text fields, panels, and action listeners to accept user input, perform calculations, and display results. Certificates are also provided to certify that the students satisfactorily completed the micro project.

Uploaded by

chakarpinil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Subject name and code: JAVA(22412) Academic Year: 2022-23

Couse Name: IF4I Semester: Fourth

A STUDY ON

Prepare A Calculator Design Using An Applet


MICRO PROJECT REPORT
Submitted in December 2023 by the group of 3 students
Sr. Roll No. Full Name of Students Enrollment Seat No.
No. ( sem-4) No. (semester-3)
1 DSD02 PINIL BABURAV CHAKAR 2209350316
2 DSD14 ROHIT RAJENDRA SONAWANE 2209350328
3 DSD10 SURAJ GURUNATH RAUT 2209350324

Under the Guidance of


PROF. MR. MAYUR KHARIK
In
Diploma Board of Technical Education,
ISO 9001:2008 (ISO/IEC-27001:201
SHIVAJIRAO S. JONDHALE POLYTECHNIC, ASANGOAN
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION,
MUMBAI

CERTIFICATES
AS
This is to certify that Mr. PINIL BABURAV CHAKAR
Roll No: DSD02 of Fourth Semester of Information Technology Programme in
Engineering & Technology at Shivajirao. S Jondhale Polytechnic Asangaon
(EAST) ShahapurS421601 has completed the Micro Project Satisfactorily in
Subject: JAVA
In the academic Year 2023 as prescribed curriculum of I Scheme.

Place: ASANGOAN Enrollment No: 2209350316


Date: / /2023 Exam Seat No:

Project Guide Heat of Department Principal

Seal of
institute
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION,
MUMBAI

CERTIFICATES

This is to certify that Mr. ROHIT RAJENDRA SONAWANE


Roll No: DSD14 of Fourth Semester of Information Technology Programme in
Engineering & Technology at Shivajirao. S Jondhale Polytechnic Asangaon
(EAST) Shahapur421601 has completed the Micro Project Satisfactorily in
Subject: JAVA
In the academic Year 2023 as prescribed curriculum of I Scheme.

Place: ASANGOAN Enrollment No: 2209350328


Date: / /2023 Exam Seat No:

Project Guide Heat of Department Principal

Seal of
institute
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION,
MUMBAI

CERTIFICATES

This is to certify that Mr. SURAJ GURUNATH RAUT


Roll No: DSD10 of Fourth Semester of Information Technology Programme in
Engineering & Technology at Shivajirao. S Jondhale Polytechnic Asangaon
(EAST) Shahapur421601 has completed the Micro Project Satisfactorily in
Subject: JAVA
In the academic Year 2023 as prescribed curriculum of I Scheme.

Place: ASANGOAN Enrollment No: 2209350324


Date: / /2023 Exam Seat No:

Project Guide Heat of Department Principal

Seal of
institute
-:Introduction:-
Problem Description :
We have to write a program in Java such that it creates a calculator which
allows basic operations of addition, subtraction, multiplication and division.

Expected Input and Output


For creating a calculator, we can have the following different sets of input and
output.

1. To Perform Addition :

When the addition expression "98+102" is typed,


it is expected that the result is displayed as "98+102=200.0".

2. To Perform Subtraction :
When the subtraction expression "200.0-58.75" is typed,
it is expected that the result is displayed as "200.0-58.75=141.25".

3. To Perform Multiplication :
Note: Join free Sanfoundry classes at Telegram or Youtube advertisement
When an multiplication expression "141.25*20" is typed,
it is expected that the result is displayed as "141.25*20=2825.0".

4. To Perform Division : When the denominator is non-zero


When an division expression "2825.0/5" is typed,
it is expected that the result is displayed as "2825.0/5=565.0".

5. To Perform Division :
When the denominator is zero
Take Java Programming Tests Now!
When an division expression "565.0/0" is typed,
it is expected that the error is displayed as "565.0/0=Zero Divison Error".
Problem Solution
1. Create a text field to accept the expression and display the output also.
2. Create buttons for digits and a decimal point.
3. Create a button to clear the complete expression.
4. Create the buttons for operations, that is for addition, subtraction,
multiplication and division and an equals button to compute the result.
5. Add ActionListener to all the buttons.
6. Compute the result and display in the text field.

Program Explanation

1. When any button on the calculator is clicked, the function actionPerformed is


called. Get the button clicked using getActionCommand.
2. If the button clicked is a digit or decimal point, then either of the following is
executed :
a) The digit is concatenated to the the second number if no operator has been
encountered.
b) Otherwise, the digit is concatenated to the first number.

3. If the button clicked is the clear button, then clear the input field.

4. If the button clicked is the equals operator, then either of the following is
executed :
a) If neither the first number nor the second number is empty, then compute the
result and display it in the frame
b) Otherwise, clear the input field.

5. If any of the button {+,-,*,/} is clicked, then either of the following is executed :
a) If either the operator or the second number is empty, then set the button clicked
as the operator.
b) Otherwise, compute the result and display it in the frame.
Source Code :

import [Link].*;

import [Link].*;

import [Link].*;

public class Calculator extends Applet implements ActionListener

String cmd[] = {"+", "-", "*", "/", "=", "C"};

int pv = 0;

String op = "";

Button b[] = new Button[16];

TextField t1 = new TextField(10);

public void init()

setLayout(new BorderLayout());

add(t1, "North");

[Link]("0");
Panel p = new Panel();

[Link](new GridLayout(4, 4));

for (int i = 0; i < 16; i++)

if (i < 10)

b[i] = new Button([Link](i));

else

b[i] = new Button(cmd[i % 10]);

b[i].setFont(new Font("Arial", [Link], 25));

[Link](b[i]);

add(p, "Center");

b[i].addActionListener(this);

public void actionPerformed(ActionEvent ae)

{
int res = 0;

String cap = [Link]();

int cv = [Link]([Link]());

if ([Link]("C"))

[Link]("0");

pv = 0; 5

cv = 0;

res = 0;

op = "";

else if ([Link]("="))

res = 0;

if (op == "+")

res = pv + cv;
else if (op == "-")

res = pv - cv;

else if (op == "*")

res = pv * cv; 6

else if (op == "/")

res = pv / cv;

[Link]([Link](res));

else if ([Link]("+") || [Link]("-") || [Link]("*") || [Link]("/"))

pv = cv;

op = cap;

[Link]("0");

else

{7
int v = cv * 10 + [Link](cap);

[Link]([Link](v));

/*

<applet code="[Link]" width=401 height=391>

</applet>

*/ 8

Output :
thank you !!!

Common questions

Powered by AI

Java applets are less common today due to several reasons: security concerns as they run in web browsers, the decline of browser support for Java plugins, and the rise of modern JavaScript frameworks and applications which offer more functionality, better UI/UX, and run directly in the browser without security risks associated with Java applets .

In the Java applet calculator, when a digit or decimal is clicked, it is concatenated to the current number unless an operator has already been encountered, in which case it is concatenated to the first number. When an operation button is clicked, it checks if an operator is already set; if not, it sets the current input as the first number and stores the operator. When equals is clicked and both numbers are valid, it calculates the result .

To construct a basic calculator using an applet in Java, key components include a text field for input and output of expressions, buttons for digits and a decimal point, a clear button, operational buttons for addition, subtraction, multiplication, division, and an equals button. Additionally, each button should have an ActionListener to handle events and compute results displayed in the text field .

The actionPerformed method is crucial for event handling in the Java-based calculator. It identifies which button was clicked using getActionCommand and performs corresponding actions: it concatenates digits to numbers, resets the input field with the clear button, performs computations with the equals operator, and sets the operation for the operational buttons if applicable .

Using Java's ActionListener interface allows for efficient, centralized event handling. Each button in the calculator can trigger specific actions without requiring multiple event listener setups, simplifying the codebase and improving maintainability. It ensures precise response to user actions in real-time .

The primary risk of not handling division by zero includes the application crashing or producing erroneous results, disrupting user experience. In Java applications, this is addressed by checking for a zero denominator before performing a division operation, ensuring that an error or an appropriate message is displayed and preventing invalid operations .

The program identifies division by zero and is expected to handle it by displaying an error message such as "Zero Division Error" instead of crashing or producing incorrect results . This involves checking for a denominator of zero before performing the division operation.

Resetting the input field after a calculation in a Java calculator application is essential to clear previous inputs, enabling the user to start a new calculation without manually deleting old results. This enhances the application's usability by providing a clean slate for each new operation .

The grid layout is used to organize the buttons in a 4x4 grid, providing a structured and consistent interface for user interaction. This approach improves usability by organizing numeric and operational buttons efficiently, making the calculator intuitive to use .

Poor UI design can lead to user confusion, usability issues, and reduced efficiency. In tools like the Java applet calculator, it could cause users to press wrong buttons or struggle with input. The current implementation addresses these issues by using a grid layout for an organized structure, clear labeling of buttons, and a responsive interface to improve user experience .

You might also like