Created
March 4, 2019 07:45
-
-
Save itssomething/f9ae9cedd609f05ebdf240707e6850a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.admin.calculator; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
import org.w3c.dom.Text; | |
public class MainActivity extends AppCompatActivity { | |
private TextView result; | |
private EditText a; | |
private EditText b; | |
private Button add ; | |
private Button sub; | |
private Button mul; | |
private Button div; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
result = (TextView)findViewById(R.id.textView); | |
a = (EditText)findViewById(R.id.editText); | |
b = (EditText)findViewById(R.id.editText2); | |
add = (Button)findViewById(R.id.button); | |
sub = (Button)findViewById(R.id.button2); | |
mul = (Button)findViewById(R.id.button3); | |
div = (Button)findViewById(R.id.button4); | |
add.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
result.setText(""); | |
if(a.getText().toString().matches("") || b.getText().toString().matches("")){ | |
result.setText(""); | |
} | |
else { | |
double temp1 = Double.parseDouble(a.getText().toString()); | |
double temp2 = Double.parseDouble(b.getText().toString()); | |
double temp3 = temp1 + temp2; | |
result.setText("" + temp3); | |
} | |
} | |
}); | |
} | |
// public void add(View view) { | |
// result.setText(""); | |
// double temp1 = Double.parseDouble(a.getText().toString()); | |
// double temp2 = Double.parseDouble(b.getText().toString()); | |
// double temp3 = temp1 + temp2; | |
// if(a.getText().toString().matches("") || b.getText().toString().matches("")){ | |
// result.setText(""); | |
// } | |
// else { | |
// result.setText("" + temp3); | |
// } | |
// } | |
public void sub(View view) { | |
result.setText(""); | |
if(a.getText().equals("") || b.getText().equals("")){ | |
result.setText(""); | |
} | |
else { | |
double temp1 = Double.parseDouble(a.getText().toString()); | |
double temp2 = Double.parseDouble(b.getText().toString()); | |
double temp3 = temp1 - temp2; | |
result.setText("" + temp3); | |
} | |
} | |
public void mul(View view) { | |
result.setText(""); | |
double temp1 = Double.parseDouble(a.getText().toString()); | |
double temp2 = Double.parseDouble(b.getText().toString()); | |
double temp3 = temp1 * temp2; | |
if(a.getText().equals("") || b.getText().equals("")){ | |
result.setText(""); | |
} | |
else { | |
result.setText("" + temp3); | |
} | |
} | |
public void div(View view) { | |
result.setText(""); | |
double temp1 = Double.parseDouble(a.getText().toString()); | |
double temp2 = Double.parseDouble(b.getText().toString()); | |
double temp3 = temp1 / temp2; | |
if(a.getText().equals("") || b.getText().equals("")){ | |
result.setText(""); | |
} | |
else { | |
result.setText("" + temp3); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment