AJP Microproject
AJP Microproject
AJP Microproject
Calculator in java(2021-2022)
SUBMITTED BY
Project Guided by
Prof.G.A.SONAWANE.
2021-2022
1
MAHAVIR POLYTECHNIC, NASHIK.
CERTIFICATE
This is to certify that the Micro Project Report on "Calculator in java"is satisfactorily
completed and submitted in the partial fulfillment of the requirement for Subject
"Advance java programming "in Third Year Computer Engineering in "Semester
Fifth" Academic Year 2021-2022.
By
Sakshi pingle
Damini sonawane
Bhavna khairnar
2
ACKNOWLEDGEMENT
I take this opportunity to thank all those who have contributed in successful
completion of this Micro Project work. I would like to express my sincere thanks to
my Project Guided by Prof.G.A.SONAWANE. who has encouraged me to work on
this project and guided me whenever required.
We also would like to express our gratitude to our H.O.D. Prof.A.D.SONAWANEfor
giving us opportunities to undertake this project works at Mahavir Polytechnic,
Nashik.
We are extremely grateful to our Principal Prof.S.V.SAGREfor his constant
inspiration and keen interest to make the project and presentation absolutely
flawless.
At the last but not the least we would like to thank our Teaching staff member,
Workshop staff member, Friends and family member for their timely co-operation
and help.
MS.sakshi pingle.
Enrollment No. 1905300038
T.Y.C.O
Academic Year 2021-22
Fifth Semester
3
Annexure – I
PART A – Micro-Project Proposal
CALCULATOR IN JAVA
4
Sr. Details of activity Planned Planned Name of Responsible
No. Start date Finish date Team Members
1 Selection topic
2 Finalizing topic
.
3 Information search
4 Information search
5 Making repot
6 Submission report
5
Annexure – II
CALCULATOR IN JAVA
1.0 Rationale
A basic calculator is able to add, subtract, multiply or divide two numbers.
This is done using a switch case.
6
7
7.0 Skill Developed / learning out of this Micro-Project
Create a simple calculator which can perform basic arithmetic operations like
addition, subtraction, multiplication or division depending upon the user
input.
2. To make it screen touch so no need to touch key buttons and one more
change which can we made is to add snaps of the person who use it.
8
INDEX
1 Introduction 10
2 Requirement analysis 10
2.1 Hardware requirements
2.2 Software requirements
3 Project planning
3.1 Schedule estimation(s/w & h/w) 11
3.2 Project plan
4 Output
4.1 program code 11-21
4.2 output of the code
5 Advantages 21
7 Conclusion 21
8 References 22
9
INTRODUCTION
RESOURCES REQUIRED
S. Name of
Specifications Qty. Remarks
No. Resource/material
Notepad, Command
1 Software 1 -
Prompt
2 RAM 1 GB 1 -
3 Hard disk 40 GB 1 -
4 Processor Pentium 1 -
10
PROJECT PLANNING
2 Finalizing topic
Sakshi pingle
3 Information search Damini sonawane
4 Information search
Bhavna khairnar.
5 Making repot
6 Submission report
PROGRAM CODE
/*********************************************
Save this file as MyCalculator.java
to compile it use
javac MyCalculator.java
to use the calcuator do this
java MyCalculator
**********************************************/
import java.awt.*;
import java.awt.event.*;
/*********************************************/
11
String digitButtonText[] = {"7", "8", "9", "4", "5", "6", "1", "2", "3", "0", "+/-", "." };
String operatorButtonText[] = {"/", "sqrt", "*", "%", "-", "1/X", "+", "=" };
String memoryButtonText[] = {"MC", "MR", "MS", "M+" };
String specialButtonText[] = {"Backspc", "C", "CE" };
12
{
memoryButton[i]=new MyMemoryButton(tempX,y,WIDTH,HEIGHT,memoryButtonT
ext[i], this);
memoryButton[i].setForeground(Color.RED);
y+=HEIGHT+V_SPACE;
}
13
operatorButton[i]=new MyOperatorButton(tempX,y,WIDTH,HEIGHT,operatorButton
Text[i], this);
operatorButton[i].setForeground(Color.RED);
if((i+1)%2==0){tempX=opsX; y+=HEIGHT+V_SPACE;}
}
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent ev)
{System.exit(0);}
});
setLayout(null);
setSize(FRAME_WIDTH,FRAME_HEIGHT);
setVisible(true);
}
//////////////////////////////////
static String getFormattedText(double temp)
{
String resText=""+temp;
if(resText.lastIndexOf(".0")>0)
resText=resText.substring(0,resText.length()-2);
return resText;
}
////////////////////////////////////////
public static void main(String []args)
{
new MyCalculator("Calculator - JavaTpoint");
}
}
/*******************************************/
14
//////////////////////////////////////////
MyDigitButton(int x,int y, int width,int height,String cap, MyCalculator clc)
{
super(cap);
setBounds(x,y,width,height);
this.cl=clc;
this.cl.add(this);
addActionListener(this);
}
////////////////////////////////////////////////
static boolean isInString(String s, char ch)
{
for(int i=0; i<s.length();i++) if(s.charAt(i)==ch) return true;
return false;
}
/////////////////////////////////////////////////
public void actionPerformed(ActionEvent ev)
{
String tempText=((MyDigitButton)ev.getSource()).getLabel();
if(tempText.equals("."))
{
if(cl.setClear)
{cl.displayLabel.setText("0.");cl.setClear=false;}
else if(!isInString(cl.displayLabel.getText(),'.'))
cl.displayLabel.setText(cl.displayLabel.getText()+".");
return;
}
int index=0;
try{
index=Integer.parseInt(tempText);
}catch(NumberFormatException e){return;}
if(cl.setClear)
15
{cl.displayLabel.setText(""+index);cl.setClear=false;}
else
cl.displayLabel.setText(cl.displayLabel.getText()+index);
}//actionPerformed
}//class defination
/********************************************/
cl.setClear=true;
double temp=Double.parseDouble(cl.displayLabel.getText());
if(opText.equals("1/x"))
{
try
{double tempd=1/(double)temp;
cl.displayLabel.setText(MyCalculator.getFormattedText(tempd));}
catch(ArithmeticException excp)
{cl.displayLabel.setText("Divide by 0.");}
return;
}
16
if(opText.equals("sqrt"))
{
try
{double tempd=Math.sqrt(temp);
cl.displayLabel.setText(MyCalculator.getFormattedText(tempd));}
catch(ArithmeticException excp)
{cl.displayLabel.setText("Divide by 0.");}
return;
}
if(!opText.equals("="))
{
cl.number=temp;
cl.op=opText.charAt(0);
return;
}
// process = button pressed
switch(cl.op)
{
case '+':
temp+=cl.number;break;
case '-':
temp=cl.number-temp;break;
case '*':
temp*=cl.number;break;
case '%':
try{temp=cl.number%temp;}
catch(ArithmeticException excp)
{cl.displayLabel.setText("Divide by 0."); return;}
break;
case '/':
try{temp=cl.number/temp;}
catch(ArithmeticException excp)
{cl.displayLabel.setText("Divide by 0."); return;}
break;
}//switch
cl.displayLabel.setText(MyCalculator.getFormattedText(temp));
17
//cl.number=temp;
}//actionPerformed
}//class
/****************************************/
/////////////////////////////////
MyMemoryButton(int x,int y, int width,int height,String cap, MyCalculator clc)
{
super(cap);
setBounds(x,y,width,height);
this.cl=clc;
this.cl.add(this);
addActionListener(this);
}
////////////////////////////////////////////////
public void actionPerformed(ActionEvent ev)
{
char memop=((MyMemoryButton)ev.getSource()).getLabel().charAt(1);
cl.setClear=true;
double temp=Double.parseDouble(cl.displayLabel.getText());
switch(memop)
{
case 'C':
cl.memLabel.setText(" ");cl.memValue=0.0;break;
case 'R':
cl.displayLabel.setText(MyCalculator.getFormattedText(cl.memValue));break;
case 'S':
cl.memValue=0.0;
case '+':
cl.memValue+=Double.parseDouble(cl.displayLabel.getText());
18
if(cl.displayLabel.getText().equals("0") || cl.displayLabel.getText().equals("0.0") )
cl.memLabel.setText(" ");
else
cl.memLabel.setText("M");
break;
}//switch
}//actionPerformed
}//class
/*****************************************/
//////////////////////////////////////////////////////////
public void actionPerformed(ActionEvent ev)
{
String opText=((MySpecialButton)ev.getSource()).getLabel();
//check for backspace button
if(opText.equals("Backspc"))
19
{
String tempText=backSpace(cl.displayLabel.getText());
if(tempText.equals(""))
cl.displayLabel.setText("0");
else
cl.displayLabel.setText(tempText);
return;
}
//check for "C" button i.e. Reset
if(opText.equals("C"))
{
cl.number=0.0; cl.op=' '; cl.memValue=0.0;
cl.memLabel.setText(" ");
}
/*********************************************
Features not implemented and few bugs
20
OUTPUT
ADVANTAGES
To make it screen touch so no need to touch key buttons and one more change
which can we made is to add snaps of the person who use it.
CONCLUSION
In this Program we are making a simple calculator that performs addition,
subtraction, multiplication and division based on the user input. The program takes
the value of both the numbers (entered by user) and then user is asked to enter the
operation (+, -, * and /), based on the input program performs the selected
operation on the entered numbers using switch case.
21
REFERENCES
1.https://www.w3schools.com/java/default.asp- From this website we got the
information about Java Programming.
3.https://www.wikihow.com/Compile-%26-Run-Java-Program-Using-Command-
Prompt - From this website we learn how to run java program in command prompt.
22
Annexure – III
Teacher Evaluation Sheet
Name of Student : Sakshi Kailas Pingle. Enrollment No:1905300038.
Name of Program: computer engineering. Semester: fifth semester.
Course Title : Advanced java programming
Code: 22517.
Course Outcomes Achieved : 1 Develop programs using GUI framework (AWT and
Swings).
2. Handle events of AWT and Swing components.
3. Develop program using database.
4. Develop program using servlets.
6 Report
Preparation
7 Presentation
8 Any other
23
S. Characteristic Poor Average Good Excellent
No. to be ( Marks ( Marks 4 - 5 ) ( Marks 6 - 8 ) ( Marks 9-
assessed 1-3 ) 10 )
(depending
upon nature
of project:
please write
indicators by
pen)
9 Defense
Note:
Every course teacher is expected to assign marks for group evolution for each group
of students in first 3 columns as per rubrics & individual evaluation in 4TH column for
each group of students as per rubrics based on viva.
Signature……………………………………………………………………………………………
24
Annexure – III
Teacher Evaluation Sheet
Name of Student : Damini Ramrao Sonawane. Enrollment No: 1905300035.
Name of Program: computer engineering. Semester: fifth semester.
Course Title : advanced java programming.
Code: 22517
6 Report
Preparation
7 Presentation
8 Any other
25
S. Characteristic Poor Average Good Excellent
No. to be ( Marks ( Marks 4 - 5 ) ( Marks 6 - 8 ) ( Marks 9-
assessed 1-3 ) 10 )
(depending
upon nature
of project:
please write
indicators by
pen)
9 Defense
Note:
Every course teacher is expected to assign marks for group evolution for each group
of students in first 3 columns as per rubrics & individual evaluation in 4TH column for
each group of students as per rubrics based on viva.
Signature……………………………………………………………………………………………
Annexure – III
26
Teacher Evaluation Sheet
Name of Student : Bhavna Ravindra khairnar. Enrollment No:170500033.
Name of Program: computer engineering. Semester: fifth semester.
Course Title : Advanced java programming
Code: 22517.
Course Outcomes Achieved : 1 Develop programs using GUI framework (AWT and
Swings).
2. Handle events of AWT and Swing components.
3. Develop program using database.
4. Develop program using servlets.
6 Report
Preparation
7 Presentation
8 Any other
(depending
27
S. Characteristic Poor Average Good Excellent
No. to be ( Marks ( Marks 4 - 5 ) ( Marks 6 - 8 ) ( Marks 9-
assessed 1-3 ) 10 )
upon nature
of project:
please write
indicators by
pen)
9 Defense
Note:
Every course teacher is expected to assign marks for group evolution for each group
of students in first 3 columns as per rubrics & individual evaluation in 4TH column for
each group of students as per rubrics based on viva.
Signature……………………………………………………………………………………………
28
29