Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Calculator. Added sub, mul and div functionalities

  • Loading branch information...
commit 8bc405601f4f5ab5ef650dd03c256a6c4d05b0e2 1 parent a4d0231
@techmaniack authored
View
31 .gitignore
@@ -0,0 +1,31 @@
+# built application files
+*.apk
+*.ap_
+
+# files for the dex VM
+*.dex
+
+# Java class files
+*.class
+
+# generated files
+bin/
+gen/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Eclipse project files
+.classpath
+.project
+
+# Proguard folder generated by Eclipse
+proguard/
+
+# Intellij project files
+*.iml
+*.ipr
+*.iws
+.idea/
+
+
View
BIN  Calculator/bin/classes.dex
Binary file not shown
View
BIN  Calculator/bin/classes/mordor/calculator/MainActivity.class
Binary file not shown
View
BIN  Calculator/bin/classes/mordor/calculator_new/R$id.class
Binary file not shown
View
BIN  Calculator/bin/classes/mordor/calculator_new/R$layout.class
Binary file not shown
View
BIN  Calculator/bin/classes/mordor/calculator_new/R$menu.class
Binary file not shown
View
BIN  Calculator/bin/classes/mordor/calculator_new/R$string.class
Binary file not shown
View
BIN  Calculator/bin/classes/mordor/calculator_new/R$style.class
Binary file not shown
View
BIN  Calculator/bin/resources.ap_
Binary file not shown
View
7 Calculator/gen/mordor/calculator_new/R.java
@@ -15,9 +15,12 @@
}
public static final class id {
public static final int button_add=0x7f070001;
- public static final int button_equate=0x7f070002;
+ public static final int button_div=0x7f070004;
+ public static final int button_equate=0x7f070005;
+ public static final int button_mul=0x7f070003;
+ public static final int button_sub=0x7f070002;
public static final int editText1=0x7f070000;
- public static final int menu_settings=0x7f070003;
+ public static final int menu_settings=0x7f070006;
}
public static final class layout {
public static final int activity_main=0x7f030000;
View
21 Calculator/res/layout/activity_main.xml
@@ -32,6 +32,27 @@
android:onClick="onAdd"/>
<Button
+ android:id="@+id/button_sub"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="-"
+ android:onClick="onSub"/>
+
+ <Button
+ android:id="@+id/button_mul"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="*"
+ android:onClick="onMul"/>
+
+ <Button
+ android:id="@+id/button_div"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="/"
+ android:onClick="onDiv"/>
+
+ <Button
android:id="@+id/button_equate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
View
62 Calculator/src/mordor/calculator/MainActivity.java
@@ -1,19 +1,22 @@
package mordor.calculator;
+import mordor.calculator_new.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
-import mordor.calculator_new.R;
+import android.widget.Toast;
public class MainActivity extends Activity {
- private EditText input ;
- private float f1,f2;
+ private EditText input;
+ private float f1, f2;
+ private int operation;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
-
+
input = (EditText) findViewById(R.id.editText1);
}
@@ -21,15 +24,56 @@ public void onAdd(View view){
//input = (EditText) findViewById(R.id.editText1);
f1 = Float.valueOf(input.getText().toString());
input.setText("");
-
+ operation=1;
}
- public void onEquate(View view){
+
+ public void onSub(View view){
+ //input = (EditText) findViewById(R.id.editText1);
+ f1 = Float.valueOf(input.getText().toString());
+ input.setText("");
+ operation=2;
+ }
+ public void onMul(View view){
+ //input = (EditText) findViewById(R.id.editText1);
+ f1 = Float.valueOf(input.getText().toString());
+ input.setText("");
+ operation=3;
+ }
+ public void onDiv(View view){
+ //input = (EditText) findViewById(R.id.editText1);
+ f1 = Float.valueOf(input.getText().toString());
+ input.setText("");
+ operation=4;
+ }
+
+
+ public void onEquate(View view) {
f2 = Float.valueOf(input.getText().toString());
String out = new String();
- out = String.valueOf(f1+f2);
-
+ switch (operation) {
+ case 1:
+ out = String.valueOf(f1 + f2);
+ break;
+ case 2:
+ out= String.valueOf(f1-f2);
+ break;
+
+ case 3:
+ out= String.valueOf(f1*f2);
+ break;
+
+ case 4:
+ if (f2 == 0){
+ Toast.makeText(this, "Divide By Zero!", Toast.LENGTH_LONG).show();
+ break;
+
+ }
+ out= String.valueOf(f1/f2);
+ break;
+ }
+
input.setText(out);
-
+
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.