0% found this document useful (0 votes)
4 views17 pages

Rescued document

The document outlines a micro project for creating a simple calculator using Java, submitted by a student at Trinity Polytechnic Pune. The calculator will perform basic arithmetic operations and feature a graphical user interface (GUI) designed with Java's Swing framework, incorporating error handling for user inputs. The project aims to reinforce programming concepts such as object-oriented design and event handling while providing a functional application for everyday use.

Uploaded by

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

Rescued document

The document outlines a micro project for creating a simple calculator using Java, submitted by a student at Trinity Polytechnic Pune. The calculator will perform basic arithmetic operations and feature a graphical user interface (GUI) designed with Java's Swing framework, incorporating error handling for user inputs. The project aims to reinforce programming concepts such as object-oriented design and event handling while providing a functional application for everyday use.

Uploaded by

Jiya Inamdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 17

/Trinity Polytechnic Pune

Program Name and Code: CO5I Academic Year: 2024-25

Course Name and Code: Advance java (22517) Semester : Fifth

MICRO PROJECT

// To create a calculator using


a java program
Submitted by :

Sr.No Roll Full Name of Enrollment Seat No


No student No

1 50 Jiya Sameer Inamdar 2217340077

Under the Guidance of

Mr.A.M.Gaikwad
in
Three Years Diploma computer Engineering & Technology of Maharashtra State Board of
Technical Education, Mumbai (Autonomous)

ISO 9001:2008 (ISO/IEC-27001:2013)

At 1734 – TRINITY POLYTECHNIC PUNE

MAHARASHTRA STATE BOARD OF TECHNICAL


EDUCATION, MUMBAI
// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

Certificate
//This is to certify that

Mr/Ms_________________________________________ Roll No ___of Fifth

semester of ____________________________Diploma.

Programme in Engineering & Technology 1734 – Trinity Polytechnic Pune,


has completed the Micro-project Satisfactorily in Subject : Advance Java
(22517) .In the Academic Year 2024-2025 as Per the MSBTE Prescribed
Curriculum of I Scheme.

Place : Pune Enrollment No :_______________

Date : / / Exam seat No : _____________

Project Guide Head of the Department Principal

INDEX

//
SR.NO Title Page .no

1. Introduction 4

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

2. Abstract 5

3. Source Code 6

4. Output 16

5. Conclusion 17

INTRODUCTION
A calculator is one of the most fundamental and widely used applications in computing, providing
users with the ability to perform basic arithmetic operations. With the growing reliance on digital
tools in everyday tasks, creating a simple yet efficient calculator program serves as a great
exercise in understanding key programming concepts. Java, being an object-oriented and
platform-independent programming language, is an ideal choice for building such applications due
to its versatility and wide range of libraries for GUI development.

This project focuses on developing a simple calculator using Java that can perform the four basic
arithmetic operations: addition, subtraction, multiplication, and division. The calculator will be
designed with a graphical user interface (GUI) using Java's Swing framework, which is part of the
Java Foundation Classes (JFC). Swing allows developers to create rich, interactive user interfaces
that are both easy to use and visually appealing.

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

The goal of this project is not only to create a functional calculator but also to provide an
opportunity to explore Java’s fundamental concepts, such as event handling, object-oriented
programming (OOP), and GUI development. The program will also incorporate basic error
handling to manage user input errors, such as division by zero or entering non-numeric values,
ensuring that the application remains robust and user-friendly.

By the end of this project, users will have a working calculator that can be used for everyday
arithmetic calculations, and developers will gain hands-on experience in creating interactive
applications with Java, laying a strong foundation for more advanced programming projects.

Abstract:

The objective of this project is to develop a simple calculator application using Java
programming. This calculator will be capable of performing basic arithmetic operations such
as addition, subtraction, multiplication, and division. The application will feature a
userfriendly graphical interface (GUI) designed using Java's Swing framework, allowing
users to input numbers and select operations intuitively. The program will include error
handling to manage invalid inputs, such as division by zero or non-numeric characters,
ensuring robustness. Additionally, the application will support basic functionalities like
clearing the screen and displaying the result of operations. This project aims to demonstrate
the practical use of Java in building interactive, user-centric applications, while reinforcing
core programming concepts such as object-oriented design, event handling, and GUI
development

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

Source Code:

import java.awt.*; import


java.awt.event.*;

public class MyCalculator extends Frame


{

public boolean setClear=true;


double number, memValue; char
op;

String digitButtonText[] = {"7", "8", "9", "4", "5", "6", "1", "2", "3", "0", "+/-", "." };

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

/
String operatorButtonText[] = {"/", "sqrt", "*", "%", "-", "1/X", "+", "=" };
String memoryButtonText[] = {"MC", "MR", "MS", "M+" };
String specialButtonText[] = {"Backspc", "C", "CE" };

MyDigitButton digitButton[]=new MyDigitButton[digitButtonText.length];


MyOperatorButton operatorButton[]=new MyOperatorButton[operatorButtonText.length];
MyMemoryButton memoryButton[]=new MyMemoryButton[memoryButtonText.length];
MySpecialButton specialButton[]=new MySpecialButton[specialButtonText.length];
Label displayLabel=new Label("0",Label.RIGHT);
Label memLabel=new Label(" ",Label.RIGHT);

final int FRAME_WIDTH=325,FRAME_HEIGHT=325; final int


HEIGHT=30, WIDTH=30, H_SPACE=10,V_SPACE=10; final int
TOPX=30, TOPY=50;

MyCalculator(String frameText)
{ super(frameText);
int tempX=TOPX,
y=TOPY;
displayLabel.setBo
unds(tempX,y,240,
HEIGHT);
displayLabel.setBa
ckground(Color.BL
UE);
displayLabel.setFor
eground(Color.WH
ITE);
add(displayLabel);

memLabel.setBounds(TOPX, TOPY+HEIGHT+ V_SPACE,WIDTH, HEIGHT);


add(memLabel);

tempX=TOPX;
y=TOPY+2*(HEIGHT+V_SPACE);

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

/
for(int i=0; i<memoryButton.length; i++)
{
memoryButton[i]=new
MyMemoryButton(tempX,y,WIDTH,HEIGHT,memoryButtonText[i], this);
memoryButton[i].setForeground(Color.RED); y+=HEIGHT+V_SPACE;
}

tempX=TOPX+1*(WIDTH+H_SPACE); y=TOPY+1*(HEIGHT+V_SPACE); for(int


i=0;i<specialButton.length;i++)
{
specialButton[i]=new MySpecialButton(tempX,y,WIDTH*2,HEIGHT,specialButtonText[i],
this);
specialButton[i].setForeground(Color.RED); tempX=tempX+2*WIDTH+H_SPACE;
}

int digitX=TOPX+WIDTH+H_SPACE; int


digitY=TOPY+2*(HEIGHT+V_SPACE);
tempX=digitX; y=digitY;

for(int i=0;i<digitButton.length;i++)

{ digitButton[i]=new MyDigitButton(tempX,y,WIDTH,HEIGHT,digitButtonText[i],
this); digitButton[i].setForeground(Color.BLUE); tempX+=WIDTH+H_SPACE;
if((i+1)%3==0){tempX=digitX; y+=HEIGHT+V_SPACE;}
}

int opsX=digitX+2*(WIDTH+H_SPACE)+H_SPACE;
int opsY=digitY; tempX=opsX; y=opsY; for(int
i=0;i<operatorButton.length;i++)
{
tempX+=WIDTH+H_SPACE;
operatorButton[i]=new

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

/
MyOperatorButton(tempX,y,WIDTH,HEIGHT,operatorButtonText[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");
}
}

class MyDigitButton extends Button implements ActionListener


{
MyCalculator cl;

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

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 (index==0 && cl.displayLabel.getText().equals("0")) return;

if(cl.setClear)
{cl.displayLabel.setText(""+index);cl.setClear=false;} else
cl.displayLabel.setText(cl.displayLabel.getText()+index);

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

/
}
}

class MyOperatorButton extends Button implements ActionListener


{
MyCalculator cl;

MyOperatorButton(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)


{
String opText=((MyOperatorButton)ev.getSource()).getLabel();

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;
}
if(opText.equals("sqrt"))
{
try
{double tempd=Math.sqrt(temp);

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

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

cl.displayLabel.setText(MyCalculator.getFormattedText(temp));
}
}
// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

class MyMemoryButton extends Button implements ActionListener {


MyCalculator cl;

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());
if(cl.displayLabel.getText().equals("0") || cl.displayLabel.getText().equals("0.0") )
cl.memLabel.setText(" ");

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

/
else
cl.memLabel.setText("M"); break;
}
}
} class MySpecialButton extends Button implements
ActionListener
{
MyCalculator cl;
MySpecialButton(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 String backSpace(String
s)
{
String Res=""; for(int i=0; i<s.length()-1; i++)
Res+=s.charAt(i); return Res;
}

public void actionPerformed(ActionEvent ev)


{
String opText=((MySpecialButton)ev.getSource()).getLabel();

if(opText.equals("Backspc"))
{
String tempText=backSpace(cl.displayLabel.getText());
if(tempText.equals(""))
cl.displayLabel.setText("0");

else
cl.displayLabel.setText(tempText);
return; }
if(opText.equals("C"))

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

/
{ cl.number=0.0; cl.op=' ';
cl.memValue=0.0; cl.memLabel.setText("
");
} cl.displayLabel.setText("0");cl.setClear=true;
}
}

OUTPUT:-
/

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

CONCLUSION
Creating a calculator in Java involves understanding fundamental programming concepts such as
control flow, user input handling, and basic arithmetic operations. Here's a high-level overview of the
key components involved:
1＀桷.Q萏֠葞֠࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀĀĀȀĀ儀ࠀༀ炄师炄㔈 ࠶㜀⨾䈀Ī䩃⩈伀J倀J
儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏ୀ葞ୀ ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ̀ĀЀĀ儀ࠀༀႄ帎ႄ㔎 ࠶㜀⨾䈀Ī䩃⩈
伀J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊ ＀桷Q萏რ葞რ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀԀĀĀ儀ࠀༀ낄帓낄㔓 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊ ＀桷Q萏 葞 ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ‫܀‬ĀȀĀ儀ࠀༀ傄帙傄㔙 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊ ＀桷⚡㗐早㖺✺å儌q⻼則Ä䃿ᐂ猀5倀@＀ǿ‫܀‬唀渀欀渀漀眀渀＀ǿࠀ＀ǿ＀ǿ＀ÿȀ＀ÿ＀ÿȀ＀ÿ‫؀‬䜀逞Ȁ‫؂‬ԃԄ̂$
.寠xী＀吀椀洀攀猀 一攀眀 刀漀洀愀渀㔀逞ȁԀąĂ؇Ԃ€匀礀洀戀漀氀㌀逮Ȁ؋ȄȂȂ$.寠xী ＀䄀爀椀愀氀㜀逮ȀԏȂЂȃ$
.篤$ূ＀䌀愀氀椀戀爀椀䌀ⰮȀ̏ȂЂȃ$.篤$ূ ＀䌀愀氀椀戀爀椀 䰀椀最栀琀䄀逞ȀԄԃ؄ȃ$¢$B鼀䌀愀洀戀爀椀愀 䴀愀琀栀
∀Ѐ㄀耈탰栀耀쮅胇쮅ÇĀȀ퐀 ꄀ,ကᨀЀ̀徐ᤀ尀/ကᨀ攀ĀჰĀ需ḅ됅됀脀ẁ0嬀4嬀4Ȁ荃ჰࠀ耀䀀PऀP  ￰ ＀ソソソソソソ䝿쑒㈀
⌀ကԀ砀砀ꀀ Input Handling: You'll need to capture user input using a Scanner object for reading numbers
and the operator from the console. This is essential for getting the necessary data to perform
calculations.
2＀桷.Q萏֠葞֠࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀĀĀȀĀ儀ࠀༀ炄师炄㔈 ࠶㜀⨾䈀Ī䩃⩈伀J倀J
儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏ୀ葞ୀ ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ̀ĀЀĀ儀ࠀༀႄ帎ႄ㔎 ࠶㜀⨾䈀Ī䩃⩈
伀J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊ ＀桷Q萏რ葞რ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀԀĀĀ儀ࠀༀ낄帓낄㔓 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊ ＀桷Q萏 葞 ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ‫܀‬ĀȀĀ儀ࠀༀ傄帙傄㔙 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊ ＀桷⚡㗐早㖺✺å儌q⻼則Ä䃿ᐂ猀5倀@＀ǿ‫܀‬唀渀欀渀漀眀渀＀ǿࠀ＀ǿ＀ǿ＀ÿȀ＀ÿ＀ÿȀ＀ÿ‫؀‬䜀逞Ȁ‫؂‬ԃԄ̂$
.寠xী＀吀椀洀攀猀 一攀眀 刀漀洀愀渀㔀逞ȁԀąĂ؇Ԃ€匀礀洀戀漀氀㌀逮Ȁ؋ȄȂȂ$.寠xী ＀䄀爀椀愀氀㜀逮ȀԏȂЂȃ$
.篤$ূ＀䌀愀氀椀戀爀椀䌀ⰮȀ̏ȂЂȃ$.篤$ূ ＀䌀愀氀椀戀爀椀 䰀椀最栀琀䄀逞ȀԄԃ؄ȃ$¢$B鼀䌀愀洀戀爀椀愀 䴀愀琀栀
∀Ѐ㄀耈탰栀耀쮅胇쮅ÇĀȀ퐀 ꄀ,ကᨀЀ̀徐ᤀ尀/ကᨀ攀ĀჰĀ需ḅ됅됀脀ẁ0嬀4嬀4Ȁ荃ჰࠀ耀䀀PऀP  ￰ ＀ソソソソソソ䝿쑒㈀
⌀ကԀ砀砀ꀀ Basic Arithmetic Operations: The core functionality of the calculator involves performing
addition, subtraction, multiplication, and division based on user input. These operations can be
implemented using if-else or switch-case statements to handle different operator choices.

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

/
3＀桷.Q萏֠葞֠࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀĀĀȀĀ儀ࠀༀ炄师炄㔈 ࠶㜀⨾䈀Ī䩃⩈伀J倀J
儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏ୀ葞ୀ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ̀ĀЀĀ儀ࠀༀႄ帎ႄ㔎 ࠶㜀⨾䈀Ī䩃⩈
伀J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏რ葞რ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀԀĀĀ儀ࠀༀ낄帓낄㔓 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏 葞 ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ‫܀‬ĀȀĀ儀ࠀༀ傄帙傄㔙 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷⚡㗐早㖺✺å儌q⻼則Ä䃿ᐂ猀5倀@＀ǿ‫܀‬唀渀欀渀漀眀渀＀ǿࠀ＀ǿ＀ǿ＀ÿȀ＀ÿ＀ÿȀ＀ÿ‫؀‬䜀逞Ȁ‫؂‬ԃԄ̂$
.寠xী＀吀椀洀攀猀 一攀眀 刀漀洀愀渀㔀逞ȁԀąĂ؇Ԃ€匀礀洀戀漀氀㌀逮Ȁ؋ȄȂȂ$.寠xী＀䄀爀椀愀氀㜀逮ȀԏȂЂȃ$
.篤$ূ＀䌀愀氀椀戀爀椀䌀ⰮȀ̏ȂЂȃ$.篤$ূ＀䌀愀氀椀戀爀椀 䰀椀最栀琀䄀逞ȀԄԃ؄ȃ$¢$B鼀䌀愀洀戀爀椀愀 䴀愀琀栀
∀Ѐ㄀耈탰栀耀쮅胇쮅ÇĀȀ퐀 ꄀ,ကᨀЀ̀徐ᤀ尀/ကᨀ攀ĀჰĀ需ḅ됅됀脀ẁ0嬀4嬀4Ȁ荃ჰࠀ耀䀀Pऀ￰  ＀ソソソソソソ䝿쑒㈀
P
⌀ကԀ砀砀ꀀ Error Handling: To improve the user experience, ensure proper error handling, such as
checking for division by zero and invalid input. This can be done through exception handling
mechanisms like try-catch blocks.
4＀桷.Q萏֠葞֠࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀĀĀȀĀ儀ࠀༀ炄师炄㔈 ࠶㜀⨾䈀Ī䩃⩈伀J倀J
儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏ୀ葞ୀ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ̀ĀЀĀ儀ࠀༀႄ帎ႄ㔎 ࠶㜀⨾䈀Ī䩃⩈
伀J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏რ葞რ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀԀĀĀ儀ࠀༀ낄帓낄㔓 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏 葞 ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ‫܀‬ĀȀĀ儀ࠀༀ傄帙傄㔙 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷⚡㗐早㖺✺å儌q⻼則Ä䃿ᐂ猀5倀@＀ǿ‫܀‬唀渀欀渀漀眀渀＀ǿࠀ＀ǿ＀ǿ＀ÿȀ＀ÿ＀ÿȀ＀ÿ‫؀‬䜀逞Ȁ‫؂‬ԃԄ̂$
.寠xী＀吀椀洀攀猀 一攀眀 刀漀洀愀渀㔀逞ȁԀąĂ؇Ԃ€匀礀洀戀漀氀㌀逮Ȁ؋ȄȂȂ$.寠xী＀䄀爀椀愀氀㜀逮ȀԏȂЂȃ$
.篤$ূ＀䌀愀氀椀戀爀椀䌀ⰮȀ̏ȂЂȃ$.篤$ূ＀䌀愀氀椀戀爀椀 䰀椀最栀琀䄀逞ȀԄԃ؄ȃ$¢$B鼀䌀愀洀戀爀椀愀 䴀愀琀栀
∀Ѐ㄀耈탰栀耀쮅胇쮅ÇĀȀ퐀 ꄀ,ကᨀЀ̀徐ᤀ尀/ကᨀ攀ĀჰĀ需ḅ됅됀脀ẁ0嬀4嬀4Ȁ荃ჰࠀ耀䀀Pऀ￰  ＀ソソソソソソ䝿쑒㈀
P
⌀ကԀ砀砀ꀀ Looping Mechanism: You can provide a way for the user to perform multiple calculations
without restarting the program by using loops (e.g., while or do-while loops) to repeatedly ask for
input until the user decides to exit.
5＀桷.Q萏֠葞֠࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀĀĀȀĀ儀ࠀༀ炄师炄㔈 ࠶㜀⨾䈀Ī䩃⩈伀J倀J
儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏ୀ葞ୀ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ̀ĀЀĀ儀ࠀༀႄ帎ႄ㔎 ࠶㜀⨾䈀Ī䩃⩈
伀J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏რ葞რ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀԀĀĀ儀ࠀༀ낄帓낄㔓 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏 葞 ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ‫܀‬ĀȀĀ儀ࠀༀ傄帙傄㔙 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷⚡㗐早㖺✺å儌q⻼則Ä䃿ᐂ猀5倀@＀ǿ‫܀‬唀渀欀渀漀眀渀＀ǿࠀ＀ǿ＀ǿ＀ÿȀ＀ÿ＀ÿȀ＀ÿ‫؀‬䜀逞Ȁ‫؂‬ԃԄ̂$
.寠xী＀吀椀洀攀猀 一攀眀 刀漀洀愀渀㔀逞ȁԀąĂ؇Ԃ€匀礀洀戀漀氀㌀逮Ȁ؋ȄȂȂ$.寠xী＀䄀爀椀愀氀㜀逮ȀԏȂЂȃ$
.篤$ূ＀䌀愀氀椀戀爀椀䌀ⰮȀ̏ȂЂȃ$.篤$ূ＀䌀愀氀椀戀爀椀 䰀椀最栀琀䄀逞ȀԄԃ؄ȃ$¢$B鼀䌀愀洀戀爀椀愀 䴀愀琀栀
∀Ѐ㄀耈탰栀耀쮅胇쮅ÇĀȀ퐀 ꄀ,ကᨀЀ̀徐ᤀ尀/ကᨀ攀ĀჰĀ需ḅ됅됀脀ẁ0嬀4嬀4Ȁ荃ჰࠀ耀䀀Pऀ￰  ＀ソソソソソソ䝿쑒㈀
P
⌀ကԀ砀砀ꀀ Modularity and Reusability: It is a good practice to organize the code into separate methods
or classes for each operation to make the program more modular and reusable. For instance, you can
create a method for each arithmetic operation.

// PAGE \* MERGEFORMAT 1 | P a g e
/Trinity Polytechnic Pune

/
6＀桷.Q萏֠葞֠࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀĀĀȀĀ儀ࠀༀ炄师炄㔈 ࠶㜀⨾䈀Ī䩃⩈伀J倀J
儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏ୀ葞ୀ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ̀ĀЀĀ儀ࠀༀႄ帎ႄ㔎 ࠶㜀⨾䈀Ī䩃⩈
伀J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏რ葞რ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀԀĀĀ儀ࠀༀ낄帓낄㔓 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷Q萏 葞 ࠵㘀 ࠷㸀*⩂䌁ᙊ䠀*䩏䩐䩑⩓帀J愀ᙊ瀀h焀૊＀＀쩲ÿ眀hĀ‫܀‬ĀȀĀ儀ࠀༀ傄帙傄㔙 ࠶㜀⨾䈀Ī䩃⩈伀
J倀J儀J匀*䩞䩡桰쩱
ÿÿ爀࣊＀桷⚡㗐早㖺✺å儌q⻼則Ä䃿ᐂ猀5倀@＀ǿ‫܀‬唀渀欀渀漀眀渀＀ǿࠀ＀ǿ＀ǿ＀ÿȀ＀ÿ＀ÿȀ＀ÿ‫؀‬䜀逞Ȁ‫؂‬ԃԄ̂$
.寠xী＀吀椀洀攀猀 一攀眀 刀漀洀愀渀㔀逞ȁԀąĂ؇Ԃ€匀礀洀戀漀氀㌀逮Ȁ؋ȄȂȂ$.寠xী＀䄀爀椀愀氀㜀逮ȀԏȂЂȃ$
.篤$ূ＀䌀愀氀椀戀爀椀䌀ⰮȀ̏ȂЂȃ$.篤$ূ＀䌀愀氀椀戀爀椀 䰀椀最栀琀䄀逞ȀԄԃ؄ȃ$¢$B鼀䌀愀洀戀爀椀愀 䴀愀琀栀
∀Ѐ㄀耈탰栀耀쮅胇쮅ÇĀȀ퐀 ꄀ,ကᨀЀ̀徐ᤀ尀/ကᨀ攀ĀჰĀ需ḅ됅됀脀ẁ0嬀4嬀4Ȁ荃ჰࠀ耀䀀Pऀ￰  ＀ソソソソソソ䝿쑒㈀
P
⌀ကԀ砀砀ꀀ User Interface: While the calculator can be built using a simple text-based interface in the
console, advanced calculators can be developed with graphical user interfaces (GUIs) using libraries
like Swing or JavaFX.

// PAGE \* MERGEFORMAT 1 | P a g e

You might also like