You are on page 1of 22

A

Micro Project
On
Calculator

Submitted in partial fulfillment of the requirement for the award of


Diploma of Engineering
in
Computer Engineering
By
Anand Chauhan
Sanjana Pawar
Rasika Shivdikar
Sagar Ansurkar
Sakshi Phadtare

Under the Guidance


Of
Pranita Redkar

Department of Computer Engineering


2023-2024

1
CERTIFICATE

VIVA COLLEGE OF DIPLOMA ENGINEERING & TECHNOLOGY


VIRAR (W)
2023-2024
This is to certify that the micro project entitled “Calculator” has been submitted Pranita Redkar
under the guidance of in partial fulfillment of the requirement for the award of Diploma of
Engineering in Computer Engineering from Maharashtra State Board of Technical Education.

“Calculator”
GROUP MEMBERS

66.Anand Chauhan
67.Sanjana Pawar
68.Rasika Shivdikar
69.Sagar Ansurkar
70.Sakshi Phadtare

Project Guide H.O. D


Prof. Pranita Redkar Prof. NIKHIL ASOLK

2
Sr. No Name of the topic Page no

PART –A PLAN

1 Brief Introduction 1

2 Aim of the Micro-Project 2

3 Action Plan 3

4 Resources Used 4

PART –B OUTCOMES

1 Brief Description 5-6

2 Aim of Micro-Project 7

3 Course Outcomes Integrated 8

4 Procedure Follow 9-13

4 Outputs of the Micro-Projects 14-18

5 Skill Developed/ learning out of this Micro-Project 19

3
Calculator AJP,22517,SemV

PART-A PLAN
1.0 Brief Introduction
____________________________________________________
It create calculator using advance java language The calculator is like a part of
every daily life, it is a very powerful and general-purpose tool. We as human beings
tend to forget many things hence calculation is also a part of it. And what makes
this project more interesting is that we are building a Scientific Calculator. Unlike
basic calculators that can only handle smaller values, a scientific calculator can
handle numbers on a much vaster scale, which can be useful when it comes to
collecting data or working as a physicist or chemist.

Viva collage of diploma engineering & technology 1


Calculator AJP,22517,SemV

2.0 AIM of Micro-Project


____________________________________________________
The Aim of the project is to create a calculator using advance java programming
language

Viva collage of diploma engineering & technology 2


Calculator AJP,22517,SemV

3.0 Action plane


____________________________________________________
Sr. Details of Activity Planned Planned Name of Responsible
No Start Finish Team Members
Date Date
1 Project selection Rutuja Mitna,Anand Chauhan,
Sanjana Pawar,Rasika Shivdikar
2 Identifying project outcomes Rutuja MitnaAnand Chauhan,
Sanjana Pawar,Rasika Shivdikar
3 Identifying resources Rutuja Mitna,Anand Chauhan,
required Sanjana Pawar,Rasika Shivdikar
4 implementation Rutuja mitna,Anand Chauhan,
Sanjana Pawar,Rasika Shivdikar
5 Final outcome Rutuja Mitna,Anand Chauhan,
Sanjana Pawar,Rasika Shivdikar
6 Documentation Rutuja Mitna,Anand Chauhan,
Sanjana Pawar,Rasika Shivdikar

7 Seminar and viva-vose Rutuja Mitna,Anand Chauhan,


Sanjana Pawar,Rasika Shivdikar

8 Final submission of Anand Chauhan,Sanjana Pawar


Microproject Rasika Shivdikar,

Viva collage of diploma engineering & technology 3


Calculator AJP,22517,SemV

4.0 Resources Required

Sr.no Name of resource Broad Quantity


specification

1 Computer system Computer i3


RAM 2 GB

2 Operating system Window

3 Develop software Jdk 1.8

Viva collage of diploma engineering & technology 4


Calculator AJP,22517,SemV

PART –B OUTCOMES
1.0 Brief Description
____________________________________________________
AWT(Abstract Window Toolkit) is an API that helps in building
GUI (Graphical User Interface) based java applications. GUI helps in user
interactions using some graphics. It primarily consists of a set of classes and
methods that are required for creatin and managing the GUI in a simplified
manner such as buttons,windows,frame,textfield,RadioButton etc
I have uses Action listener interface for EventHandling.
Numeric button
when any of the numeric button pressed whatever value in label l1 will be
What ever value in label l1 will be stored in a variable zt and then concatenated
with the corresponding number and and then displayed in the label l1
for NEGATIVE and DECIMAL PTS Button we did it similarly
Arithmetic button
NOW here we store the value of label l1 into a variable num1 after converting
into double type which will be technically 1st number
and then and set label l1 to null we will just use a check variable for getting
that this particular airthmetic button(here +) was clicked so we can do this
operation in our = button
Equal button
NOW again store the value of l1 into num2 variable which will be
techincally 2nd number
and then check the value of variable check and then do corresponding
operation and after that display result in label l1
Clear button
here updated all the variable we use to its Default value 0
and set label l1 to null so that we can start our new calculation afterward
what I did is just handled one execption in EQUAL and
all AIRTHMETIC Buttons and printed a desired message according to
situtation
when we was converting the value into the double value, BUT lets say that,
label l1 has null value (i.e. label is empty) and we still pressed these button
then it will generate NumberFormatException execption,
So handled that and printed desired message

Viva collage of diploma engineering & technology 5


Calculator AJP,22517,SemV

For eg:
If I click1 then + and then i click - instead of some other numeric button, hence
this an invalid format, and when -was clicked at that time label was null hence
execption generated so just handled it and printed invalid format inlabel
SIMILARLY, when label is null,and = was clicked in that situation ENTER
NUMBER FIRST will be displayed inside label

Viva collage of diploma engineering & technology 6


Calculator AJP,22517,SemV

2.0 AIM of Micro-Project


____________________________________________________
The Aim of the project is to create a calculator using advance java programming
language

Viva collage of diploma engineering & technology 7


Calculator AJP,22517,SemV

3.0 Course Outcomes (CO)


____________________________________________________
1. Develop program using GUI framework
2. Handle event of AWT and Swing Component
3. Develop program to handle event in java programming

Viva collage of diploma engineering & technology 8


Calculator AJP,22517,SemV

4.0 Procedure Followed

Code of Calculator.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Calculator implements ActionListener{

JFrame frame;
JTextField textfield;
JButton[] numberButtons = new JButton[10];
JButton[] functionButtons = new JButton[9];
JButton addButton,subButton,mulButton,divButton;
JButton decButton, equButton, delButton, clrButton, negButton;
JPanel panel;

Font myFont = new Font("Ink Free",Font.BOLD,30);

double num1=0,num2=0,result=0;
char operator;

Calculator(){

frame = new JFrame("Calculator");


frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420, 550);
frame.setLayout(null);

textfield = new JTextField();


textfield.setBounds(50, 25, 300, 50);
textfield.setFont(myFont);
textfield.setEditable(false);

addButton = new JButton("+");


subButton = new JButton("-");
Viva collage of diploma engineering & technology 9
Calculator AJP,22517,SemV

mulButton = new JButton("*");


divButton = new JButton("/");
decButton = new JButton(".");
equButton = new JButton("=");
delButton = new JButton("Del");
clrButton = new JButton("Clr");
negButton = new JButton("(-)");

functionButtons[0] = addButton;
functionButtons[1] = subButton;
functionButtons[2] = mulButton;
functionButtons[3] = divButton;
functionButtons[4] = decButton;
functionButtons[5] = equButton;
functionButtons[6] = delButton;
functionButtons[7] = clrButton;
functionButtons[8] = negButton;

for(int i =0;i<9;i++) {
functionButtons[i].addActionListener(this);
functionButtons[i].setFont(myFont);
functionButtons[i].setFocusable(false);
}

for(int i =0;i<10;i++) {
numberButtons[i] = new JButton(String.valueOf(i));
numberButtons[i].addActionListener(this);
numberButtons[i].setFont(myFont);
numberButtons[i].setFocusable(false);
}

negButton.setBounds(50,430,100,50);
delButton.setBounds(150,430,100,50);
clrButton.setBounds(250,430,100,50);

panel = new JPanel();


panel.setBounds(50, 100, 300, 300);

Viva collage of diploma engineering & technology 10


Calculator AJP,22517,SemV

panel.setLayout(new GridLayout(4,4,10,10));

panel.add(numberButtons[1]);
panel.add(numberButtons[2]);
panel.add(numberButtons[3]);
panel.add(addButton);
panel.add(numberButtons[4]);
panel.add(numberButtons[5]);
panel.add(numberButtons[6]);
panel.add(subButton);
panel.add(numberButtons[7]);
panel.add(numberButtons[8]);
panel.add(numberButtons[9]);
panel.add(mulButton);
panel.add(decButton);
panel.add(numberButtons[0]);
panel.add(equButton);
panel.add(divButton);

frame.add(panel);
frame.add(negButton);
frame.add(delButton);
frame.add(clrButton);
frame.add(textfield);
frame.setVisible(true);
}

public static void main(String[] args) {

Calculator calc = new Calculator();


}

@Override
public void actionPerformed(ActionEvent e) {

for(int i=0;i<10;i++) {
if(e.getSource() == numberButtons[i]) {

Viva collage of diploma engineering & technology 11


Calculator AJP,22517,SemV

textfield.setText(textfield.getText().concat(String.valueOf(i)));
}
}
if(e.getSource()==decButton) {
textfield.setText(textfield.getText().concat("."));
}
if(e.getSource()==addButton) {
num1 = Double.parseDouble(textfield.getText());
operator ='+';
textfield.setText("");
}
if(e.getSource()==subButton) {
num1 = Double.parseDouble(textfield.getText());
operator ='-';
textfield.setText("");
}
if(e.getSource()==mulButton) {
num1 = Double.parseDouble(textfield.getText());
operator ='*';
textfield.setText("");
}
if(e.getSource()==divButton) {
num1 = Double.parseDouble(textfield.getText());
operator ='/';
textfield.setText("");
}
if(e.getSource()==equButton) {
num2=Double.parseDouble(textfield.getText());

switch(operator) {
case'+':
result=num1+num2;
break;
case'-':
result=num1-num2;
break;
case'*':

Viva collage of diploma engineering & technology 12


Calculator AJP,22517,SemV

result=num1*num2;
break;
case'/':
result=num1/num2;
break;
}
textfield.setText(String.valueOf(result));
num1=result;
}
if(e.getSource()==clrButton) {
textfield.setText("");
}
if(e.getSource()==delButton) {
String string = textfield.getText();
textfield.setText("");
for(int i=0;i<string.length()-1;i++) {
textfield.setText(textfield.getText()+string.charAt(i));
}
}
if(e.getSource()==negButton) {
double temp = Double.parseDouble(textfield.getText());
temp*=-1;
textfield.setText(String.valueOf(temp));
}
}
}

Viva collage of diploma engineering & technology 13


Calculator AJP,22517,SemV

6.0 Outputs of Micro-Projects

Calculator:

Viva collage of diploma engineering & technology 14


Calculator AJP,22517,SemV

1)Addition of 2+1:

Viva collage of diploma engineering & technology 15


Calculator AJP,22517,SemV

2)Substraction of 3-1:

Viva collage of diploma engineering & technology 16


Calculator AJP,22517,SemV

3)Multiply of 5*2:

Viva collage of diploma engineering & technology 17


Calculator AJP,22517,SemV

4)Division of 6/2:

Viva collage of diploma engineering & technology 18


Calculator AJP,22517,SemV

6.0 Skill Developed


____________________________________________________
Thus we have studied how to make calculator from advance java programming
language Developing skills with a calculator can be helpful in various areas,
including mathematics, finance, and general problem-solving

Viva collage of diploma engineering & technology 19

You might also like