Вы находитесь на странице: 1из 6

if(!cond.

equals("multiply")) {
before = (String) answer.getText();
cond = "multiply";
disp = true;
}else if(disp2 && !clicked){
equalClick(view);
cond = "multiply";
disp = true;
clicked = true;
}

double x;
double y;
if(cond.equals("multiply")){
x = Double.parseDouble(answer.getText().toString());
y = Double.parseDouble(before);
x *= y;
answer.setText("" + x);
before = (String) answer.getText();
disp = false;
cond = "";
}else if(cond.equals("subtract")){
x = Double.parseDouble(answer.getText().toString());
y = Double.parseDouble(before);
y -= x;
answer.setText("" + y);
before = (String) answer.getText();
disp = false;
cond = "";
}else if(cond.equals("add")){
x = Double.parseDouble(answer.getText().toString());
y = Double.parseDouble(before);
x += y;
answer.setText("" + x);
before = (String) answer.getText();
disp = false;
cond = "";
}

package com.example.gateway.myapplication;
import
import
import
import
import
import
import
import

android.content.res.Resources;
android.support.v7.app.ActionBarActivity;
android.os.Bundle;
android.util.Log;
android.util.TypedValue;
android.view.Menu;
android.view.MenuItem;
android.view.View;

import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
TextView zero;
TextView one;
TextView two;
TextView three;
TextView four;
TextView five;
TextView six;
TextView seven;
TextView eight;
TextView nine;
TextView multiply;
TextView subtract;
TextView add;
TextView equal;
TextView clear;
TextView point;
TextView answer;
String before;
String cond;
boolean disp;
boolean disp2;
boolean clicked;
private static final String TAG = "hello";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
zero = (TextView) findViewById(R.id.zero);
one = (TextView) findViewById(R.id.one);
two = (TextView) findViewById(R.id.two);
three = (TextView) findViewById(R.id.three);
four = (TextView) findViewById(R.id.four);
five = (TextView) findViewById(R.id.five);
six = (TextView) findViewById(R.id.six);
seven = (TextView) findViewById(R.id.seven);
eight = (TextView) findViewById(R.id.eight);
nine = (TextView) findViewById(R.id.nine);
multiply = (TextView) findViewById(R.id.multiply);
subtract = (TextView) findViewById(R.id.subtract);
add = (TextView) findViewById(R.id.add);
equal = (TextView) findViewById(R.id.equal);
clear = (TextView) findViewById(R.id.clear);
point = (TextView) findViewById(R.id.point);
answer = (TextView) findViewById(R.id.answer);
Resources r = getResources();
int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15
0, r.getDisplayMetrics());
zero.setTextSize(px);
one.setTextSize(px);
two.setTextSize(px);
three.setTextSize(px);
four.setTextSize(px);
five.setTextSize(px);
six.setTextSize(px);

seven.setTextSize(px);
eight.setTextSize(px);
nine.setTextSize(px);
multiply.setTextSize(px);
subtract.setTextSize(px);
add.setTextSize(px);
equal.setTextSize(px);
clear.setTextSize(px);
point.setTextSize(px);
answer.setTextSize(px);
cond = new String("");
disp = false;
disp2 = false;
clicked = false;
}
public void zeroClick(View view){
String x = (String) answer.getText();
if(x.equals("69") || x.equals("0")){
answer.setText("0");
}else{
x += "0";
answer.setText(x);
}
}
public void oneClick(View view){
String x = (String) answer.getText();
if(x.equals("69")){
answer.setText("1");
}else{
x += "1";
answer.setText(x);
}
}
public void twoClick(View view){
String x = (String) answer.getText();
if(x.equals("69")){
answer.setText("2");
}else{
x += "2";
answer.setText(x);
}
}
public void threeClick(View view){
String x = (String) answer.getText();
if(x.equals("69")){
answer.setText("3");
}else{
x += "3";
answer.setText(x);
}
}
public void fourClick(View view){
String x = (String) answer.getText();
if(x.equals("69")){
answer.setText("4");

}else{
x += "4";
answer.setText(x);
}
}
public void fiveClick(View view){
String x = (String) answer.getText();
if(x.equals("69")){
answer.setText("5");
}else{
x += "5";
answer.setText(x);
}
}
public void sixClick(View view){
String x = (String) answer.getText();
if(x.equals("69")){
answer.setText("6");
}else if(cond.equals("multiply")){
answer.setText("6");
disp2 = true;
clicked = false;
}else if (cond.equals("add")){
answer.setText("6");
disp2 = true;
clicked = false;
}else if(cond.equals("subtract")){
answer.setText("6");
disp2 = true;
clicked = false;
}
else{
x += "6";
answer.setText(x);
}
}
public void sevenClick(View view){
String x = (String) answer.getText();
if(x.equals("69")){
answer.setText("7");
}else if(cond.equals("multiply")){
answer.setText("7");
disp2 = true;
clicked = false;
}else if (cond.equals("add")){
answer.setText("7");
disp2 = true;
clicked = false;
}else if(cond.equals("subtract")){
answer.setText("7");
disp2 = true;
clicked = false;
}
else{
x += "7";
answer.setText(x);
}

}
public void eightClick(View view){
String x = (String) answer.getText();
if(x.equals("69")){
answer.setText("8");
}else{
x += "8";
answer.setText(x);
}
}
public void nineClick(View view){
String x = (String) answer.getText();
if(x.equals("69")){
answer.setText("9");
}else{
x += "9";
answer.setText(x);
}
}
public void multiplyClick(View view){
}
public void subtractClick(View view){
}
public void addClick(View view){
}
public void pointClick(View view){
boolean a = false;
String x = (String) answer.getText();
for(int i = 0; i < x.length(); i++){
if(x.charAt(i)=='.'){
a = true;
}
}
if(x.equals("69") || a){}
else{
x += ".";
answer.setText(x);
}
}
public void equalClick(View view){
answer.setText("8===D~~")
}
public void clearClick(View view){
answer.setText("69");
cond = "";
before = "";
disp = false;
disp2 = false;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@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);
}
}