Professional Documents
Culture Documents
mycalc2;
import
import
import
import
import
import
import
android.app.Activity;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.widget.Button;
android.widget.TextView;
if (unit > 2)
{
temp1 = temp1 * unit + Double.parseDouble((bt.getText().toSt
ring()));
}
else
{
temp1 = Double.parseDouble(bt.getText().toString());
}
unit =10;
check=0;
}
if(num==temp5){
num++;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
double temp1=0;
double temp2=0;
double temp3=0;
static short operationToDo=0;
public void operators(View sender)
{
Button bt=(Button)sender;
if(check!=1)
{
op++;
temp5++;
}
unit = 1;
unit2 = .1;
Dot = 1;
textView2.append(bt.getText());
switch (operationToDo) {
case 0:
temp2 = temp2 + temp1 + temp3;
break;
case 1:
{
Button bt=(Button)sender;
if(bt.getText().toString().equals("C"))
{
temp1=0;
temp2=0;
temp3=0;
temp4=5;
temp5=0;
num=0;
op=0;
check=1;
operationToDo=0;
textView.setText("");
textView2.setText("");
isempty=true;
unit=1;
unit2=.1;
Dot=1;
}
}
public void equals(View sender)
{
Button bt=(Button)sender;
if(bt.getText().toString().equals("="))
if(num!=op)
{
if (temp4 == 0)
{
temp2 = temp2 + temp1 + temp3;
}
if (temp4 == 1)
{
temp2 = temp2 - temp1 - temp3;
}
if (temp4 == 2)
{
temp2 = temp2 *(temp1 + temp3);
}
if (temp4 == 3)
{
temp2 = temp2 / (temp1 + temp3);
}
}
if(op==0 && )
{
textView.setText(textView2.getText());
}
else {
textView.setText(Double.toString(temp2));
}
textView2.setText("");
temp1=0;
temp3=0;
temp4=5;
temp5=0;
num=0;
op=0;
unit=1;
unit2=.1;
Dot=1;
check=1;
}
}
int l=digit.length();
delchar=digit.charAt(l);
textView2.setText(digit);
if (delchar == '1' || delchar== '2' || delchar== '3' || delchar== '4' ||
delchar== '5'
|| delchar== '6' || delchar== '7' || delchar== '8' || delchar==
'9' )
{
deleted = deleted+ digit.charAt(l);
digit = digit.substring(0, digit.length() - 1);
}
else
{
if(delchar == '+')
{
textView2.setText(digit);
temp2=temp2-Integer.parseInt(deleted);
}
}
}