JAVA
JAVA
JAVA
A STUDY ON
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.
Seal of
institute
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION,
MUMBAI
CERTIFICATES
Seal of
institute
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION,
MUMBAI
CERTIFICATES
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.
1. To Perform Addition :
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".
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
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 java.applet.*;
import java.awt.*;
import java.awt.event.*;
int pv = 0;
String op = "";
setLayout(new BorderLayout());
add(t1, "North");
t1.setText("0");
Panel p = new Panel();
if (i < 10)
else
p.add(b[i]);
add(p, "Center");
b[i].addActionListener(this);
{
int res = 0;
int cv = Integer.parseInt(t1.getText());
if (cap.equals("C"))
t1.setText("0");
pv = 0; 5
cv = 0;
res = 0;
op = "";
else if (cap.equals("="))
res = 0;
if (op == "+")
res = pv + cv;
else if (op == "-")
res = pv - cv;
res = pv * cv; 6
res = pv / cv;
t1.setText(String.valueOf(res));
pv = cv;
op = cap;
t1.setText("0");
else
{7
int v = cv * 10 + Integer.parseInt(cap);
t1.setText(String.valueOf(v));
/*
</applet>
*/ 8
Output :
thank you !!!