DAY 27
1
Mobile Development

## DAY27 第一個完整程式練習，一台計算機!(二)

``````    public void think(){
if(record == 0){
plus = temp;
num = 0;
tempplus = plus + num2;
plus = tempplus;
num2 = 0;
temp = plus;
}else if(record == 1){
if (temp == 0) {
negetive = temp;
num=0;
tempnegetive = num2;
}else {
negetive = temp;
num = 0;
tempnegetive = negetive - num2;
}
negetive = tempnegetive;
num2 =0;
temp = negetive;
}else if(record == 2){
if(temp == 0 && num2!=0){
temp = 1;
}
time = temp;
num = 0;
if(num2!=0) {
temptime = time * num2;
}else {
temptime = time;
}
time = temptime;
num2 = 0;
temp = time;
}else if(record == 3){
if(temp == 0){
temp = 1;
devide = temp;
num = 0;
tempdevide = num2 / devide;
}else {
devide = temp;
num = 0;
tempdevide = devide / num2;
}
devide = tempdevide;
num2 = 0;
temp = devide;
}
}
``````

``````    public void plus(View view){
if (record == 5){
record = 0;
}
think();
recordplus = 0;
record = 0;
number.setText( temp+"+");
warming++;
warm();
}
``````

5是起始值，所以會變成0，如果不是5會讓think做上個運算符號，再把record變成0，而think會做加號部分，把之前的數字和新抓到的數字num2相加，再把結果存起來，warm的部分之後再講

``````    public void negetive(View view){
if (record == 5){
record = 1;
}
think();
recordnegetive = 0;
record = 1;
number.setText( temp + "-");
warming++;
warm();
}
``````

think裡的做法就是，先判斷temp是否為0，是就讓tempnegetive等於num2，不是就tempnegetive = negetive - num2，最後數字存到temp裡。