Uploaded by edwin1975garcia

Android Activity 1 BasicMathApp

advertisement
Page 1 of 3
Android App User Interface Exercise
Android App Name: MathOperApp
App Descriptions: Android application program that will allow the user to input two
integer numbers and display the answer using the basic mathematical operations
addition, subtraction, multiplication and division.
Screen Design:
Initial Screen Output
After entering numbers
and Clicking Sum Button
Source Code: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Mathematical Operations" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" >
Mobile App 1 – Activity 1 | BasicMathApp
Prepared by: Edwin S. Garcia
Page 2 of 3
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
<Button
android:id="@+id/btnAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sum/Addition" />
<Button
android:id="@+id/btnSub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subtraction" />
<Button
android:id="@+id/btnMul"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Multiplication" />
<Button
android:id="@+id/btnDiv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Division" />
<TextView
android:id="@+id/txtViewAns"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Source Code: MainActivity.java
package com.bsit.basicmathapp;
import
import
import
import
import
import
androidx.appcompat.app.AppCompatActivity;
android.os.Bundle;
android.view.View;
android.widget.Button;
android.widget.EditText;
android.widget.TextView;
Mobile App 1 – Activity 1 | BasicMathApp
Prepared by: Edwin S. Garcia
Page 3 of 3
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create objects
Button btnA = (Button)
Button btnS = (Button)
Button btnM = (Button)
Button btnD = (Button)
findViewById(R.id.btnAdd);
findViewById(R.id.btnSub);
findViewById(R.id.btnMul);
findViewById(R.id.btnMul);
final EditText txtN1 = (EditText) findViewById(R.id.editText1);
final EditText txtN2 = (EditText) findViewById(R.id.editText2);
final TextView txtAns = (TextView)
findViewById(R.id.txtViewAns);
// Create button Click event
btnA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int n1 = new Integer(txtN1.getText().toString());
int n2 = new Integer(txtN2.getText().toString());
int ans = n1 + n2;
txtAns.setText("The answer of " + n1 + " + " + n2 + " =
" + ans);
}
});
}
}
General Instructions:






Complete the android application and make sure all basic mathematical operations
are working.
You are allowed to change object names and variable names to make your
solution unique and not copy paste from others solution.
Comments can be used to document your source code and solutions.
Challenge: Add two (2) new buttons for Modulo (remainder) operations and Clear
button to clear all the text fields and answers.
You can add additional labels for your group members name to be included in the
output (ie. <Member1, Member2, … MemberN>
Compressed your solution (Android Project) folder using WinRar or WinZip and
named it Act1GrpX.rar (Note: Replace X with your group number) upload with
your PDF Documentation on the ELMS assigned DropBox as part of your Group
Graded Activities in 3rd Quarter Grading.
Good Luck and God Speed!
Mobile App 1 – Activity 1 | BasicMathApp
Prepared by: Edwin S. Garcia
Related documents
Download