Friday, August 4, 2017

Android application for calculating using complex calculator.



/*******************************************************************************************
Program Name: Write an android application for calculating using complex calculator.
Author: sujith
Date: 1/10/2016
*******************************************************************************************/

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sujithbaby.calci">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="25dp"
android:background="#0856A4"

tools:context="com.example.sujithbaby.calci.MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
android:layout_margin="25dp"
android:background="#ffffff"
android:id="@+id/txt1"
android:gravity="end"
android:layout_alignParentEnd="true" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:textSize="25dp"
android:layout_margin="25dp"
android:text="0"
android:gravity="end"
android:layout_below="@+id/txt1"
android:id="@+id/ed1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ed1"
android:text="1"
android:id="@+id/one"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ed1"
android:layout_toRightOf="@+id/one"
android:text="2"
android:id="@+id/two"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ed1"
android:layout_toRightOf="@+id/two"
android:text="3"
android:id="@+id/three"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ed1"
android:layout_toRightOf="@+id/three"
android:text="+"
android:id="@+id/plus"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/one"
android:text="4"
android:id="@+id/four"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/one"
android:layout_toRightOf="@+id/four"
android:text="5"
android:id="@+id/five"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/one"
android:layout_toRightOf="@+id/five"
android:text="6"
android:id="@+id/six"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/one"
android:layout_toRightOf="@+id/six"
android:text="-"
android:id="@+id/minus"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/four"
android:text="7"
android:id="@+id/seven"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/four"
android:layout_toRightOf="@+id/seven"
android:text="8"
android:id="@+id/eight"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/four"
android:layout_toRightOf="@+id/eight"
android:text="9"
android:id="@+id/nine"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/four"
android:layout_toRightOf="@+id/nine"
android:text="*"
android:id="@+id/multi"/>
<Button
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="@+id/seven"
android:text="0"
android:id="@+id/zero"/>
<Button
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_below="@+id/seven"
android:layout_toRightOf="@+id/zero"
android:text="."
android:id="@+id/dot"/>
<Button
android:layout_width="72dp"
android:layout_height="wrap_content"
android:layout_below="@+id/seven"
android:layout_toRightOf="@+id/dot"
android:text="="
android:id="@+id/equals"/>
<Button
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_below="@+id/seven"
android:layout_toRightOf="@+id/equals"
android:text="/"
android:id="@+id/divide"/>
<Button
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_below="@+id/seven"
android:layout_toRightOf="@+id/divide"
android:text="C"
android:id="@+id/cancel"/>
</RelativeLayout>


MainActivity.java
package com.example.sujithbaby.calci;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
private Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0,b_add,b_sub,b_div,b_multi,b_deci,b_cancel,b_equals;
private TextView final_result,textView;
private Boolean decimal=false,add=false,substract=false,multiply=false,divide=false,notinitial=false,equalcalculated=false;
private String string1,string2,changedsym="",lastsymbol="";
private Double number1=0.0,number2=0.0,result=0.0,beforevalue=0.0,aftervalue=0.0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b0=(Button)findViewById(R.id.zero);
b1=(Button)findViewById(R.id.one);
b2=(Button)findViewById(R.id.two);
b3=(Button)findViewById(R.id.three);
b4=(Button)findViewById(R.id.four);
b5=(Button)findViewById(R.id.five);
b6=(Button)findViewById(R.id.six);
b7=(Button)findViewById(R.id.seven);
b8=(Button)findViewById(R.id.eight);
b9=(Button)findViewById(R.id.nine);
b_add=(Button)findViewById(R.id.plus);
b_sub=(Button)findViewById(R.id.minus);
b_multi=(Button)findViewById(R.id.multi);
b_div=(Button)findViewById(R.id.divide);
b_cancel=(Button)findViewById(R.id.cancel);
b_deci=(Button)findViewById(R.id.dot);
b_equals=(Button)findViewById(R.id.equals);
final_result=(TextView)findViewById(R.id.ed1);
textView=(TextView)findViewById(R.id.txt1);
b0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(equalcalculated!=true){
if(textView.getText().equals("")&&final_result.getText().equals("0")){
final_result.setText("0");
textView.setText("0");
aftervalue=Double.parseDouble(final_result.getText().toString());
}
else if(add==false && substract==false && divide==false && multiply==false){
final_result.setText(final_result.getText()+"0");
if(notinitial==false){
aftervalue=Double.parseDouble(final_result.getText().toString());
String finalst=final_result.getText().toString();
textView.setText(finalst);
}
}
else{
checkSymbolSelected();
beforevalue=Double.parseDouble(final_result.getText().toString());
notinitial=true;
final_result.setText("0");
aftervalue=Double.parseDouble(final_result.getText().toString());
add=false;
substract=false;
multiply=false;
divide=false;
}
}
else{
clearall();
final_result.setText("0");
textView.setText("0");
}
}
});
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(equalcalculated!=true){
if(textView.getText().equals("")&&final_result.getText().equals("0")){
final_result.setText("1");
textView.setText("1");
aftervalue=Double.parseDouble(final_result.getText().toString());

}
else if(add==false && substract==false && divide==false && multiply==false){
final_result.setText(final_result.getText()+"1");
if(notinitial==false){
aftervalue=Double.parseDouble(final_result.getText().toString());
String finalst=final_result.getText().toString();
textView.setText(finalst);
}

}
else{
checkSymbolSelected();
beforevalue=Double.parseDouble(final_result.getText().toString());
notinitial=true;
final_result.setText("1");
aftervalue=Double.parseDouble(final_result.getText().toString());
add=false;
substract=false;
multiply=false;
divide=false;
}
}
else{
clearall();
final_result.setText("1");
textView.setText("1");
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(equalcalculated!=true){
if(textView.getText().equals("")&&final_result.getText().equals("0")){
final_result.setText("2");
textView.setText("2");
aftervalue=Double.parseDouble(final_result.getText().toString());

}
else if(add==false && substract==false && divide==false && multiply==false){
final_result.setText(final_result.getText()+"2");
if(notinitial==false){
aftervalue=Double.parseDouble(final_result.getText().toString());
String finalst=final_result.getText().toString();
textView.setText(finalst);
}

}
else{
checkSymbolSelected();
beforevalue=Double.parseDouble(final_result.getText().toString());
notinitial=true;
final_result.setText("2");
aftervalue=Double.parseDouble(final_result.getText().toString());
add=false;
substract=false;
multiply=false;
divide=false;
}
}
else{
clearall();
final_result.setText("2");
textView.setText("2");
}

}
});
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(equalcalculated!=true){
if(textView.getText().equals("")&&final_result.getText().equals("0")){
final_result.setText("3");
textView.setText("3");
aftervalue=Double.parseDouble(final_result.getText().toString());

}
else if(add==false && substract==false && divide==false && multiply==false){
final_result.setText(final_result.getText()+"3");
if(notinitial==false){
aftervalue=Double.parseDouble(final_result.getText().toString());
String finalst=final_result.getText().toString();
textView.setText(finalst);
}

}
else{
checkSymbolSelected();
beforevalue=Double.parseDouble(final_result.getText().toString());
notinitial=true;
final_result.setText("3");
aftervalue=Double.parseDouble(final_result.getText().toString());
add=false;
substract=false;
multiply=false;
divide=false;
}
}
else{
clearall();
final_result.setText("2");
textView.setText("2");
}
}
});
b4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(equalcalculated!=true){
if(textView.getText().equals("")&&final_result.getText().equals("0")){
final_result.setText("4");
textView.setText("4");
aftervalue=Double.parseDouble(final_result.getText().toString());
}
else if(add==false && substract==false && divide==false && multiply==false){
final_result.setText(final_result.getText()+"4");
if(notinitial==false){
aftervalue=Double.parseDouble(final_result.getText().toString());
String finalst=final_result.getText().toString();
textView.setText(finalst);
}
}
else{
checkSymbolSelected();
beforevalue=Double.parseDouble(final_result.getText().toString());
notinitial=true;
final_result.setText("4");
aftervalue=Double.parseDouble(final_result.getText().toString());
add=false;
substract=false;
multiply=false;
divide=false;
}
}
else{
clearall();
final_result.setText("4");
textView.setText("4");
}
}
});
b5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(equalcalculated!=true){
if(textView.getText().equals("")&&final_result.getText().equals("0")){
final_result.setText("5");
textView.setText("5");
aftervalue=Double.parseDouble(final_result.getText().toString());

}
else if(add==false && substract==false && divide==false && multiply==false){
final_result.setText(final_result.getText()+"5");
if(notinitial==false){
aftervalue=Double.parseDouble(final_result.getText().toString());
String finalst=final_result.getText().toString();
textView.setText(finalst);
}

}
else{
checkSymbolSelected();
beforevalue=Double.parseDouble(final_result.getText().toString());
notinitial=true;
final_result.setText("2");
aftervalue=Double.parseDouble(final_result.getText().toString());
add=false;
substract=false;
multiply=false;
divide=false;
}
}
else{
clearall();
final_result.setText("5");
textView.setText("5");
}
}
});
b6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(equalcalculated!=true){
if(textView.getText().equals("")&&final_result.getText().equals("0")){
final_result.setText("6");
textView.setText("6");
aftervalue=Double.parseDouble(final_result.getText().toString());

}
else if(add==false && substract==false && divide==false && multiply==false){
final_result.setText(final_result.getText()+"6");
if(notinitial==false){
aftervalue=Double.parseDouble(final_result.getText().toString());
String finalst=final_result.getText().toString();
textView.setText(finalst);
}

}
else{
checkSymbolSelected();
beforevalue=Double.parseDouble(final_result.getText().toString());
notinitial=true;
final_result.setText("6");
aftervalue=Double.parseDouble(final_result.getText().toString());
add=false;
substract=false;
multiply=false;
divide=false;
}
}
else{
clearall();
final_result.setText("6");
textView.setText("6");
}
}
});
b7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(equalcalculated!=true){
if(textView.getText().equals("")&&final_result.getText().equals("0")){
final_result.setText("7");
textView.setText("7");
aftervalue=Double.parseDouble(final_result.getText().toString());

}
else if(add==false && substract==false && divide==false && multiply==false){
final_result.setText(final_result.getText()+"7");
if(notinitial==false){
aftervalue=Double.parseDouble(final_result.getText().toString());
String finalst=final_result.getText().toString();
textView.setText(finalst);
}

}
else{
checkSymbolSelected();
beforevalue=Double.parseDouble(final_result.getText().toString());
notinitial=true;
final_result.setText("7");
aftervalue=Double.parseDouble(final_result.getText().toString());
add=false;
substract=false;
multiply=false;
divide=false;
}
}
else{
clearall();
final_result.setText("7");
textView.setText("7");
}
}
});
b8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(equalcalculated!=true){
if(textView.getText().equals("")&&final_result.getText().equals("0")){
final_result.setText("8");
textView.setText("8");
aftervalue=Double.parseDouble(final_result.getText().toString());

}
else if(add==false && substract==false && divide==false && multiply==false){
final_result.setText(final_result.getText()+"8");
if(notinitial==false){
aftervalue=Double.parseDouble(final_result.getText().toString());
String finalst=final_result.getText().toString();
textView.setText(finalst);
}

}
else{
checkSymbolSelected();
beforevalue=Double.parseDouble(final_result.getText().toString());
notinitial=true;
final_result.setText("8");
aftervalue=Double.parseDouble(final_result.getText().toString());
add=false;
substract=false;
multiply=false;
divide=false;
}
}
else{
clearall();
final_result.setText("8");
textView.setText("8");
}
}
});
b9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(equalcalculated!=true){
if(textView.getText().equals("")&&final_result.getText().equals("0")){
final_result.setText("9");
textView.setText("9");
aftervalue=Double.parseDouble(final_result.getText().toString());

}
else if(add==false && substract==false && divide==false && multiply==false){
final_result.setText(final_result.getText()+"9");
if(notinitial==false){
aftervalue=Double.parseDouble(final_result.getText().toString());
String finalst=final_result.getText().toString();
textView.setText(finalst);
}
}
else{
checkSymbolSelected();
beforevalue=Double.parseDouble(final_result.getText().toString());
notinitial=true;
final_result.setText("9");
aftervalue=Double.parseDouble(final_result.getText().toString());
add=false;
substract=false;
multiply=false;
divide=false;
}
}
else{
clearall();
final_result.setText("9");
textView.setText("9");
}
}
});
b_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lastsymbol="";
if(equalcalculated==true){
textView.setText(final_result.getText().toString());
equalcalculated=false;
}
if(equalcalculated!=true){
String text=textView.getText().toString();

if(text.equals("")&&final_result.getText().toString().equals("0")){
textView.setText("");
final_result.setText("0");
}else{
if((text.endsWith("+")&& add==true||text.endsWith("-")&& substract==true||text.endsWith("*")&& multiply==true)||text.endsWith("/")&& divide==true){
if(!(textView.getText().toString()==null)||(textView.getText())=="0"){
String newstring=textView.getText().toString();
newstring=newstring.substring(0,newstring.length()-1);
textView.setText(newstring+ "+");
changedsym="+";
add=true;
substract=false;
multiply=false;
divide=false;
}
}
String final_string_text=(final_result.getText().toString());
if(!(final_string_text.endsWith("+"))){
if(add==false){
if(number1!=0.0){
number2=Double.parseDouble(final_result.getText().toString());
string2=final_result.getText().toString();
string1=textView.getText().toString();
add=true;
decimal=false;
if(changedsym.equals("+")){
result=number1+number2;
}else if (changedsym.equals("-")){
result=number1-number2;
}else if (changedsym.equals("*")){
result=number1*number2;
}else if (changedsym.equals("/")){
result=number1/number2;
}
textView.setText(string1.concat(string2)+"+");
changedsym="+";
number1=result;
final_result.setText(Double.toString(result));

}else{
number1=Double.parseDouble(final_result.getText().toString());
if(number1==0.0){
textView.setText("");
final_result.setText("0");
}else{
textView.setText(textView.getText()+"+");
add=true;
decimal=false;
changedsym="+";
}
}
}
}
}
}else {
clearall();
}
}
});
b_sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lastsymbol="";
if(equalcalculated==true){
textView.setText(final_result.getText().toString());
equalcalculated=false;
}
if(equalcalculated!=true){
String text=textView.getText().toString();

if(text.equals("")&&final_result.getText().toString().equals("0")){
textView.setText("");
final_result.setText("0");
}else{
if((text.endsWith("+")&& add==true||text.endsWith("-")&& substract==true||text.endsWith("*")&& multiply==true)||text.endsWith("/")&& divide==true){
if(!(textView.getText().toString()==null)||(textView.getText())=="0"){
String newstring=textView.getText().toString();
newstring=newstring.substring(0,newstring.length()-1);
textView.setText(newstring+ "-");
changedsym="-";
add=false;
substract=true;
multiply=false;
divide=false;
}
}
String final_string_text=(final_result.getText().toString());
if(!(final_string_text.endsWith("-"))){
if(add==false){
if(number1!=0.0){
number2=Double.parseDouble(final_result.getText().toString());
string2=final_result.getText().toString();
string1=textView.getText().toString();
add=true;
decimal=false;
if(changedsym.equals("+")){
result=number1+number2;
}else if (changedsym.equals("-")){
result=number1-number2;
}else if (changedsym.equals("*")){
result=number1*number2;
}else if (changedsym.equals("/")){
result=number1/number2;
}
textView.setText(string1.concat(string2)+"-");
changedsym="-";
number1=result;
final_result.setText(Double.toString(result));

}else{
number1=Double.parseDouble(final_result.getText().toString());
if(number1==0.0){
textView.setText("");
final_result.setText("0");
}else{
textView.setText(textView.getText()+"-");
substract=true;
decimal=false;
changedsym="-";
}
}
}
}
}
}else {
clearall();
}
}
});
b_multi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

lastsymbol="";
if(equalcalculated==true){
textView.setText(final_result.getText().toString());
equalcalculated=false;
}
if(equalcalculated!=true){
String text=textView.getText().toString();
if(text.equals("")&&final_result.getText().toString().equals("0")){
textView.setText("");
final_result.setText("0");
}else{
if((text.endsWith("+")&& add==true||text.endsWith("-")&& substract==true||text.endsWith("*")&& multiply==true)||text.endsWith("/")&& divide==true){
if(!(textView.getText().toString()==null)||(textView.getText())=="0"){
String newstring=textView.getText().toString();
newstring=newstring.substring(0,newstring.length()-1);
textView.setText(newstring+ "*");
changedsym="*";
multiply=true;
substract=false;
add=false;
divide=false;
}
}
String final_string_text=(final_result.getText().toString());
if(!(final_string_text.endsWith("*"))){
if(add==false){
if(number1!=0.0){
number2=Double.parseDouble(final_result.getText().toString());
string2=final_result.getText().toString();
string1=textView.getText().toString();
add=true;
decimal=false;
if(changedsym.equals("+")){
result=number1+number2;
}else if (changedsym.equals("-")){
result=number1-number2;
}else if (changedsym.equals("*")){
result=number1*number2;
}else if (changedsym.equals("/")){
result=number1/number2;
}
textView.setText(string1.concat(string2)+"*");
changedsym="*";
number1=result;
final_result.setText(Double.toString(result));

}else{
number1=Double.parseDouble(final_result.getText().toString());
if(number1==0.0){
textView.setText("");
final_result.setText("0");
}else{
textView.setText(textView.getText()+"*");
multiply=true;
decimal=false;
changedsym="*";
}
}
}
}
}
}else {
clearall();
}

}
});
b_div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lastsymbol="";
if(equalcalculated==true){
textView.setText(final_result.getText().toString());
equalcalculated=false;
}
if(equalcalculated!=true){
String text=textView.getText().toString();
if(text.equals("")&&final_result.getText().toString().equals("0")){
textView.setText("");
final_result.setText("0");
}else{
if((text.endsWith("+")&& add==true||text.endsWith("-")&& substract==true||text.endsWith("*")&& multiply==true)||text.endsWith("/")&& divide==true){
if(!(textView.getText().toString()==null)||(textView.getText())=="0"){
String newstring=textView.getText().toString();
newstring=newstring.substring(0,newstring.length()-1);
textView.setText(newstring+ "/");
changedsym="/";
add=true;
substract=false;
multiply=false;
divide=false;
}
}
String final_string_text=(final_result.getText().toString());
if(!(final_string_text.endsWith("/"))){
if(add==false){
if(number1!=0.0){
number2=Double.parseDouble(final_result.getText().toString());
string2=final_result.getText().toString();
string1=textView.getText().toString();
divide=true;
decimal=false;
if(changedsym.equals("+")){
result=number1+number2;
}else if (changedsym.equals("-")){
result=number1-number2;
}else if (changedsym.equals("*")){
result=number1*number2;
}else if (changedsym.equals("/")){
result=number1/number2;
}
textView.setText(string1.concat(string2)+"/");
changedsym="/";
number1=result;
final_result.setText(Double.toString(result));

}else{
number1=Double.parseDouble(final_result.getText().toString());
if(number1==0.0){
textView.setText("");
final_result.setText("0");
}else{
textView.setText(textView.getText()+"/");
divide=true;
decimal=false;
changedsym="/";
}
}
}
}
}
}else {
clearall();
}

}
});
b_deci.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (equalcalculated != true){
if (textView.getText().equals("") && final_result.getText().equals("0")){
final_result.setText("0.");
textView.setText("0.");
aftervalue = Double.parseDouble(final_result.getText().toString());
decimal = true;

}else if (add==false && divide==false && multiply==false && substract==false){
System.out.println("Decimal Status"+decimal);
if (decimal==false){
final_result.setText(final_result.getText()+".");
decimal=true;
}
if (notinitial == false) {
aftervalue = Double.parseDouble(final_result.getText().toString());
String finalstr = final_result.getText().toString();
textView.setText(finalstr);
}
} else {

beforevalue = Double.parseDouble(final_result.getText().toString());

notinitial = true;

if (decimal==false){
final_result.setText("");
final_result.setText("0.");
decimal=true;
}
aftervalue = Double.parseDouble(final_result.getText().toString());
add = false;
substract = false;
multiply = false;
divide = false;
}
} else {
clearall();
decimal=true;
}
}
});
b_equals.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String finalstring=Double.toString(aftervalue);
if(finalstring.endsWith(".")){
finalstring=finalstring.substring(0,finalstring.length()-1);
final_result.setText(finalstring);
}
if(lastsymbol.equals("+")){
final_result.setText(Double.toString(beforevalue+aftervalue));
}else if (lastsymbol.equals("-")){
final_result.setText(Double.toString(beforevalue-aftervalue));
}else if (lastsymbol.equals("*")){
final_result.setText(Double.toString(beforevalue*aftervalue));
}else if (lastsymbol.equals("/")){
final_result.setText(Double.toString(beforevalue/aftervalue));
}else{
final_result.setText(Double.toString(beforevalue+aftervalue));
}
clearall();
equalcalculated=true;
decimal=true;
}
});
b_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clearall();
final_result.setText("0");
}
});

}

public void checkSymbolSelected(){
if(add==true){
lastsymbol="+";
}
else if(substract==true){
lastsymbol="-";
}
else if(multiply==true){
lastsymbol="*";
}
else if(divide==true){
lastsymbol="/";
}
}
public void clearall(){
textView.setText("");
add=false;
substract=false;
multiply=false;
divide=false;
notinitial=false;
equalcalculated=false;
number1=0.0;
number2=0.0;
result=0.0;
changedsym="";
notinitial=false;
beforevalue=0.0;
aftervalue=0.0;
decimal=false;
equalcalculated=false;
lastsymbol="";

}
}


OUTPUT


No comments:

Post a Comment