OOPM Mini Project Report
CALCULATOR WITH METRIC
CONVERTER USING JAVA
Submitted in partial fulfillment of the
requirements of the S. E Semester III in
degree of Bachelor of Computer
Engineering
BY
Name of Group Members
GUPTA NAMRATA JAYSHANKAR(CS_10)
KHAN RUSHQA SHER
MOHAMMED(CS_16) DUBEY VISHAL
YOGESH (CS_07)
Guide [Link]. HARSHA DAVE
Department Of Computer Engineering
Shree L. R. Tiwari College Of Engineering
Kanakia Park, Mira Road (E), Thane -401 107, Maharashtra.
October 2022
Table of Contents
1. Introduction
2. System Architecture (If any)
3. Implementation
4. Results
5. Conclusion
6. References
1. Introduction
The Calculator application performs basic
operations". The application provides user an option
to choose between the basic mode and metric mode"
based on the option selected by the user, the
application calls the corresponding class and the user
can perform various mathematical operations
provided in the class".There is a base class in the
application which contains all the methods for
calculation, basic as well as metric convert function".
The application validates the user input also and
provides appropriate messages when wrong input is
given by the user. Also in this application we have
added a function which converts the units i.e. we can
convert Centimeter to Meter and Meter to Centimeter
using Calci () methode.
BASIC FUNCTION
Addition: The addition (sum function) is used by clicking on the
“+” button or using the keyboard. The function results in a+b.
Subtraction: The subtraction (minus function) is used by clicking
on the “-” button or using a keyboard. The function results a-b.
Multiplication: The multiplication (times function) is used by
clicking on the “x” button or using a keyboard. The function
results a*b.
Division: The division (divide function) is used by clicking on the
“/” button or using the keyboard. The function results a/b.
Metric Convert: The metric convert function converts the units
i.e. Centimeter to Meter or Meter to Centimeter.
3. Implementation
CODE:
import [Link].*;
import [Link].*;
import [Link];
class Calci extends WindowAdapter implements ActionListener{
Frame f;
Label l1,l2,l3;
JComboBox<String> c1,c2;
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0;
Button badd,bsub,bmult,bdiv,bmod,bcalc,bclr,bpts,bneg,bback,bcon;
double xd;
double num1,num2,check;
Calci(){
f= new Frame("MY CALCULATOR");
// INSTANTIATING COMPONENETS
l1=new Label("",[Link]);
[Link](Color.LIGHT_GRAY);
[Link](50,50,260,60);
l2=new Label("FROM");
[Link](50,125,40,15);
l3=new Label("TO");
[Link](210,125,40,15);
String ops1[]=
{"Centimeter","Meter"}; String
ops2[]= {"Meter","Centimeter"};
c1=new JComboBox<String>(ops1);
[Link](50,142,100,30);
c2=new JComboBox<String>(ops2);
[Link](210,142,100,30);
b1=new Button("1");
[Link](50,450,50,50);
b2=new Button("2");
[Link](120,450,50,50);
b3=new Button("3");
[Link](190,450,50,50);
b4=new Button("4");
[Link](50,380,50,50);
b5=new Button("5");
[Link](120,380,50,50);
b6=new Button("6");
[Link](190,380,50,50);
b7=new Button("7");
[Link](50,310,50,50);
b8=new Button("8");
[Link](120,310,50,50);
b9=new Button("9");
[Link](190,310,50,50);
b0=new Button("0");
[Link](120,520,50,50);
bneg=new Button("+/-");
[Link](50,520,50,50);
bpts=new Button(".");
[Link](190,520,50,50);
bback=new Button("back");
[Link](120,240,50,50);
badd=new Button("+");
[Link](260,450,50,50);
bsub=new Button("-");
[Link](260,380,50,50);
bmult=new Button("*");
[Link](260,310,50,50);
bdiv=new Button("/");
[Link](260,240,50,50);
bmod=new Button("%");
[Link](190,240,50,50);
bcalc=new Button("=");
[Link](245,520,65,50);
bclr=new Button("CE");
[Link](50,240,65,50);
bcon=new Button("CONVERT");
[Link](115,192,130,30);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
//ADDING TO FRAME
[Link](l1);
[Link](l2);
[Link](l3);
[Link](c1);
[Link](c2);
[Link](b1); [Link](b2); [Link](b3); [Link](b4); [Link](b5);[Link](b6); [Link](b7);
[Link](b8);[Link](b9);[Link](b0);
[Link](badd); [Link](bsub); [Link](bmod); [Link](bmult);
[Link](bdiv); [Link](bmod);[Link](bcalc);[Link](bcon);
[Link](bclr); [Link](bpts);[Link](bneg); [Link](bback);
[Link](360,610);
[Link](null);
[Link](true);
}
//FOR CLOSING THE WINDOW
public void windowClosing(WindowEvent e) {
[Link]();
}
public void actionPerformed(ActionEvent e)
{ String z,zt;
if([Link]()==bcon) {
String m=(String)[Link]();
String n=(String)[Link]();
if(m=="Centimeter" && n=="Meter")
{
try{zt=[Link]();
double x=[Link](zt);
[Link](x+"cm = "+
(x*0.01)+"m");
}catch(NumberFormatException f){
[Link]("Invalid Format");
return;
}
}
if(m=="Meter" && n=="Centimeter")
{ try{zt=[Link]();
double x=[Link](zt);
[Link](x+"m = "+
(x*100)+"cm");
}catch(NumberFormatException f){
[Link]("Invalid Format");
return;
}
}
if(m=="Meter" && n=="Meter")
{ try{zt=[Link]();
double x=[Link](zt);
[Link](x+"m = "+x+"m");
}catch(NumberFormatException f){
[Link]("Invalid Format");
return;
}
}
if(m=="Centimeter" && n=="Centimeter") {
try{zt=[Link]();
double x=[Link](zt);
[Link](x+"cm = "+x+"cm");
}catch(NumberFormatException f){
[Link]("Invalid Format");
return;
}
}
}
//NUMBER BUTTON
if([Link]()==b1){
zt=[Link]();
z=zt+"1";
[Link](z);
}
if([Link]()==b2){
zt=[Link]();
z=zt+"2";
[Link](z);
}
if([Link]()==b3){
zt=[Link]();
z=zt+"3";
[Link](z);
}
if([Link]()==b4){
zt=[Link]();
z=zt+"4";
[Link](z);
}
if([Link]()==b5){
zt=[Link]();
z=zt+"5";
[Link](z);
}
if([Link]()==b6){
zt=[Link]();
z=zt+"6";
[Link](z);
}
if([Link]()==b7){
zt=[Link]();
z=zt+"7";
[Link](z);
}
if([Link]()==b8){
zt=[Link]();
z=zt+"8";
[Link](z);
}
if([Link]()==b9){
zt=[Link]();
z=zt+"9";
[Link](z);
}
if([Link]()==b0){
zt=[Link]();
z=zt+"0";
[Link](z);
}
if([Link]()==bpts){ //ADD DECIMAL PTS
zt=[Link]();
z=zt+".";
[Link](z);
}
if([Link]()==bneg){ //FOR NEGATIVE
zt=[Link]();
z="-"+zt;
[Link](z);
}
if([Link]()==bback){ // FOR BACKSPACE
zt=[Link]();
try{
z=[Link](0, [Link]()-1);
}catch(StringIndexOutOfBoundsException f){return;}
[Link](z);
}
//AIRTHMETIC BUTTON
if([Link]()==badd){ //FOR ADDITION
try{
num1=[Link]([Link]());
}catch(NumberFormatException f){
[Link]("Invalid Format");
return;
}
z="";
[Link](z);
check=1;
}
if([Link]()==bsub){ //FOR SUBTRACTION
try{
num1=[Link]([Link]());
}catch(NumberFormatException f){
[Link]("Invalid Format");
return;
}
z="";
[Link](z);
check=2;
}
if([Link]()==bmult){ //FOR MULTIPLICATION
try{
num1=[Link]([Link]());
}catch(NumberFormatException f){
[Link]("Invalid Format");
return;
}
z="";
[Link](z);
check=3;
}
if([Link]()==bdiv){ //FOR DIVISION
try{
num1=[Link]([Link]());
}catch(NumberFormatException f){
[Link]("Invalid Format");
return;
}
z="";
[Link](z);
check=4;
}
if([Link]()==bmod){ //FOR MOD/REMAINDER
try{
num1=[Link]([Link]());
}catch(NumberFormatException f){
[Link]("Invalid Format");
return;
}
z="";
[Link](z);
check=5;
}
//RESULT BUTTON
if([Link]()==bcalc){
try{
num2=[Link]([Link]());
}catch(Exception f){
[Link]("ENTER NUMBER FIRST ");
return;
}
if(check==1)
xd =num1+num2;
if(check==2)
xd =num1-num2;
if(check==3)
xd =num1*num2;
if(check==4)
xd =num1/num2;
if(check==5)
xd =num1%num2;
[Link]([Link](xd));
}
//FOR CLEARING THE LABEL and Memory
if([Link]()==bclr){
num1=0;
num2=0;
check=0;
xd=0;
z="";
[Link](z);
}
}
//MAIN METHOD where objects of MyCalc is instantaiated
public static void main(String args[]){
new Calci();
}
}
Technologies Used
● JAVA: All codes have been written using the java
programming language.
● NETBEANS: This project has developed inside of the
Apache Netbeans IDE 14.
4. Results
5. Conclusion:
● By implementing this program we have created a
calculator functioning on basic operations like addition,
subtraction, multiplication and division.
● In this calculator we can convert the units centimeter to
meter and meter to centimeter.
6. References:
[Link]
[Link]
[Link]