Implementing the claculate() method in Calculator Application

The calculate() method is called, when any of the arithmetical methods is executed, such as addition, subtraction, division multiplication and pow from the calculator application interface The calculate() method is defined in the Calculator_app class.

Declaration of the methods calculate()



public void calculate()
{
double l=0;
int o=0;
String opp="";
str2=str;
str="0";
m=Double.valueOf(str1).doubleValue();
n=Double.valueOf(str2).doubleValue();
opp=op;
if (op.compareTo("+")==0)
{
l=m+n;
  op="";
}
  else if (op.compareTo("-")==0)
 {
  l=m-n;
  op="";
}
 else if (op.compareTo("*")==0)
 {
        l=m*n;
  op="";
 }
 else if (op.compareTo("/")==0)
 {
    l=m/n;
    op="";
  }
  else if (op.compareTo("")==0)
 {
    l=Double.valueOf(str2).doubleValue();
  }
  else if (op.compareTo("Pow")==0)
 {
    o=Integer.valueOf(str2).intValue();
    l=Math_class.pow_func(m,o);
    op="";
 }
 cond5=true;
 pressed=true;//pressed=true specify the
 //End user has pressed a symbol key such as, +, -, /.
 str=""+l;
 textf.setText(str);
 f.CreateFile();
 f.addTofile(str1+opp+str2+"="+l);
}//End of method declaration "calculate".

The abouve listing shows the declartion of the Calculate() method. The calculate() methods is invoked by keyPressed(), keyTyped() and actionPerfomed methods. The calculator() method is invoked the end user presses addition, subtraction, division, multiplication and power button on the calculator interface.


0 Comments:

Post a Comment