Skip to content

Commit e860df6

Browse files
committed
Finishing touches to the calculation methods.
1 parent 03b545a commit e860df6

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

app/src/main/java/com/example/daymian/calculator/MainActivity.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ public class MainActivity extends AppCompatActivity {
1414

1515
// Declaring sum things
1616
private TextView screen;
17-
private String str1, str2, result, str, sign;
18-
private double a, b;
17+
private String str1;
18+
private String str2;
19+
private String result;
20+
private String str;
21+
private String sign = "";
22+
public double a;
23+
public double b;
24+
25+
public double[] thing;
1926

2027
@Override
2128
protected void onCreate(Bundle savedInstanceState) {
@@ -32,17 +39,29 @@ public void onClick(View view) {
3239
Button number = (Button)view;
3340
str = number.getText().toString();
3441
screen.setText(str);
35-
a = Double.parseDouble(str);
42+
43+
if (sign.equals("")) {
44+
a = Double.parseDouble(str);
45+
} else {
46+
b = Double.parseDouble(str);
47+
}
48+
3649
}
3750

3851
public void onClickSigns(View view) {
3952
Button operand = (Button)view;
53+
screen.setText(sign);
4054
sign = operand.getText().toString();
4155

4256
if (sign.contains("AC")) {
4357
screen.setText("0");
4458
a = 0.0;
4559
b = 0.0;
60+
sign = "";
61+
result = "";
62+
} else if (sign.contains("+/-")) {
63+
a = (-1 * a);
64+
screen.setText(a + "");
4665
} else {
4766
screen.setText(sign);
4867
str = "";
@@ -68,13 +87,11 @@ else if(sign.equals("/")) {
6887
}
6988
else if(sign.equals("%")) {
7089
result = (a % b) + "";
71-
}
72-
else if(sign.equals("+/-")) {
73-
result = (-1 * a) + "";
74-
}
75-
else {
90+
} else {
7691
result = "wrong";
7792
}
7893
screen.setText(result);
94+
a = Double.parseDouble(result);
95+
sign = "";
7996
}
8097
}

0 commit comments

Comments
 (0)