Está en la página 1de 17

POLITEKNIK KUCHING SARAWAK

KM 22, JALAN MATANG,


93050 KUCHING, SARAWAK
TEL: 082-845596
http://www.poliku.edu.my

INFORMATION TECHNOLOGY &


COMMUNICATION DEPARTMENT
FP533: MOBILE APPLICATION DEVELOPMENT
PROBLEM BASED TASK REPORT
BASIC CALCULATOR
PREPARED BY:
NURUL ALIAH SYAHIDAH BINTI HUT 05DIP13F2018
NURNADYRA AFYZZA BINTI SUZALEE 05DIP13F2030
LECTURERS NAME:
MR ZAKIR HUSSAIN


Introduction

Nowadays, many basic calculator app has been developed to ease user to
calculate something that involving numbers that can take anywhere and use
anytime..Before the basic calculator app has been create,user using the electronic
calculator which is a small portable electronic device used to perform both basic
operations of arithmetic and complex mathematical.But regarding of developing the
basic calculatorapp,theseinventionarenotonlyforthecalculationpurposejustlikethe
the electronic calculator device but this basic calculator app are together in the user
handphone with other app that user can using just touch the screen without only
bringingtheelectroniccalculatordeviceforallthetime.
The
BasicCalculator app (Figure 1.0) calculates and displays the calculations
between the two numbers that the user entered. As the user enters each digit of a
number by touching the
numeric keypad
, they will need to click one of the arithmetic
operationsthatareprovidedoneoftheinterfacestogetthetotaloftheircalculations.
Android Studio software isbeingused todevelopthisapplication.Wehaveused
IceCreamSandwich4.0andSDK15.

SOURCECODE:

MainActivity.java

package
leya.example.org.basiccalculator

import
android.support.v7.app.AppCompatActivity
import
android.os.Bundle
import
android.view.Menu
import
android.view.MenuItem
import
android.view.View
import
android.widget.EditText
import
android.widget.Toast

publicclass
MainActivity
extends
AppCompatActivity{

private
EditText
num1
,
num2

@Override

protectedvoid
onCreate(BundlesavedInstanceState){

super
.onCreate(savedInstanceState)
setContentView(R.layout.
activity_main
)

num1
=(EditText)findViewById(R.id.
editText
)

num2
=(EditText)findViewById(R.id.
editText2
)

@Override


publicboolean
onCreateOptionsMenu(Menumenu){

//Inflatethemenuthisaddsitemstotheactionbar
ifitispresent.

getMenuInflater().inflate(R.menu.
menu_main
,menu)

returntrue

@Override

publicboolean
onOptionsItemSelected(MenuItemitem){

//Handleactionbaritemclickshere.Theactionbar
will
//automaticallyhandleclicksontheHome/Upbutton,so
long
//asyouspecifyaparentactivityin
AndroidManifest.xml.

int
id=item.getItemId()

//noinspectionSimplifiableIfStatement

if
(id==R.id.
action_settings
){

returntrue

returnsuper
.onOptionsItemSelected(item)
}

publicvoid
sumar(Viewv){

int
n1=Integer.
parseInt
(
num1
.getText().toString())

int
n2=Integer.
parseInt
(
num2
.getText().toString())

int
total=n1+n2
mostrar(total)
}

publicvoid
restar(Viewv){

int
n1=Integer.
parseInt
(
num1
.getText().toString())

int
n2=Integer.
parseInt
(
num2
.getText().toString())

int
total=n1n2
mostrar(total)
}

publicvoid
multiplicar(Viewv){

int
n1=Integer.
parseInt
(
num1
.getText().toString())

int
n2=Integer.
parseInt
(
num2
.getText().toString())

int
total=n1*n2
mostrar(total)
}

publicvoid
dividir(Viewv){

int
n1=Integer.
parseInt
(
num1
.getText().toString())

int
n2=Integer.
parseInt
(
num2
.getText().toString())

int
total=
0

if
(n2<=
0
){
total=
0

}
else
{
total=n1/n2
}
mostrar(total)
}

privatevoid
mostrar(
int
total){

Toast.
makeText
(MainActivity.
this
,
"Total="
+total,
Toast.
LENGTH_LONG
).show()
}
}

activity_main.xml

<
LinearLayout
xmlns:
android
=
"http://schemas.android.com/apk/res/android"

xmlns:
tools
=
"http://schemas.android.com/tools"

android
:layout_width=
"match_parent"

android
:layout_height=
"match_parent"

android
:orientation=
"vertical"

tools
:context=
".MainActivity"
>

<
LinearLayout

android
:orientation=
"horizontal"

android
:layout_width=
"match_parent"

android
:layout_height=
"wrap_content"
>

<
TextView

android
:layout_width=
"wrap_content"

android
:layout_height=
"wrap_content"

android
:text=
"@string/number1"

android
:id=
"@+id/textView"
/>

<
EditText

android
:layout_width=
"fill_parent"

android
:layout_height=
"wrap_content"

android
:inputType=
"number"

android
:ems=
"10"

android
:id=
"@+id/editText"
/>
</
LinearLayout
>

<
LinearLayout

android
:orientation=
"horizontal"

android
:layout_width=
"match_parent"

android
:layout_height=
"wrap_content"
>

<
TextView

android
:layout_width=
"wrap_content"

android
:layout_height=
"wrap_content"

android
:text=
"@string/number2"

android
:id=
"@+id/textView2"
/>

<
EditText

android
:layout_width=
"fill_parent"

android
:layout_height=
"wrap_content"

android
:inputType=
"number"

android
:ems=
"10"

android
:id=
"@+id/editText2"
/>
</
LinearLayout
>

<
LinearLayout

android
:orientation=
"horizontal"

android
:layout_width=
"match_parent"

android
:layout_height=
"wrap_content"
>

<
Button

android
:layout_width=
"wrap_content"

android
:layout_height=
"wrap_content"

android
:text=
"@string/btnSumar"

android
:id=
"@+id/button"

android
:onClick=
"sumar"

android
:background=
"#ff789a"
/>


<
Button

android
:layout_width=
"wrap_content"

android
:layout_height=
"wrap_content"

android
:text=
"@string/btnRestar"

android
:id=
"@+id/button2"

android
:onClick=
"restar"

android
:background=
"#ffb9dd"
/>

<
Button

android
:layout_width=
"wrap_content"

android
:layout_height=
"wrap_content"

android
:text=
"@string/btnMultiplicar"

android
:id=
"@+id/button3"

android
:onClick=
"multiplicar"

android
:background=
"#FFFF789A"
/>

<
Button

android
:layout_width=
"wrap_content"

android
:layout_height=
"wrap_content"

android
:text=
"@string/btnDividir"

android
:id=
"@+id/button4"

android
:onClick=
"dividir"

android
:background=
"#FFFFB9DD"
/>
</
LinearLayout
>
</
LinearLayout
>


AndroidManifest.xml

<?
xmlversion=
"1.0"
encoding=
"utf8"
?>
<
manifest
xmlns:
android
=
"http://schemas.android.com/apk/res/android"

package=
"leya.example.org.basiccalculator"
>

<
usessdk

android
:minSdkVersion=
"15"
android
:targetSdkVersion=
"15"
/>

<
application

android
:allowBackup=
"true"

android
:icon=
"@mipmap/ic_launcher"

android
:label=
"@string/app_name"

android
:theme=
"@style/AppTheme"
>
<
activity

android
:name=
".MainActivity"

android
:label=
"@string/app_name"
>
<
intentfilter
>
<
action
android
:name=
"android.intent.action.MAIN"
/>

<
category
android
:name=
"android.intent.category.LAUNCHER"
/>
</
intentfilter
>
</
activity
>
</
application
>


</
manifest
>

strings.xml

<
resources
>
<
string

name=
"app_name"
>BasicCalculator</
string
>

<
string

name=
"action_settings"
>Settings</
string
>
<
string

name=
"number1"
>Number1:</
string
>
<
string

name=
"number2"
>Number2:</
string
>
<
string

name=
"btnSumar"
>+</
string
>
<
string

name=
"btnRestar"
></
string
>
<
string

name=
"btnMultiplicar"
>*</
string
>
<
string

name=
"btnDividir"
>/</
string
>
</
resources
>


OUTPUT:

Interface

Figure1.0:Theabovefigureshowstheinterfaceofthecalculator

The calculator consists of fourdifferentkindsof arithmeticoperations which are


addition, subtraction, multiplicationanddivision.TheuserneedtotouchtheEditTextin
Number1tofillinthenumber16andnext,Number2forthenumber52.Afterfilltheboth
numbers.usercanchooseanyoperationtogettotal.

Process1:Addition

Figure1.2:Theabovefigureshowstheprocessofaddition

For the first process,whenthe userenterthenumber12forthefirstemptyspace


and the fill the second empty space with number 11,after that user will click on the
addition to getthetotal forboth number.When theprocessadditionsuccess,thedialog
popupthetotalofbothnumberis23.

Process2:Subtraction

Figure1.3:Theabovefigureshowstheprocessofsubtraction

For the second,whentheuserenter thenumber25forthefirstemptyspaceand


the fill thesecond emptyspace withnumber 11,after that user will clickon theaddition
to get thetotal forbothnumber.When theprocesssubtractionis successful,thedialog
popupthetotalofbothnumberis14.


Process3:Multiplication

Figure1.4:Theabovefigureshowstheprocessofmultiplication

Next,for the third process,when the user enter the number 15 forthe firstempty
space and the fill the second empty space with number11,afterthat userwillclick on
the addition togetthetotalforbothnumber.Whentheprocesssubtractionissuccessful,
thedialogpopupthetotalofbothnumberis165.

Process4:Division

Figure1.5:Theabovefigureshowstheprocessofdivision

Finally forthe last process,whenthe user enterthenumber15forthefirstempty


spaceand thefillthe secondemptyspacewithnumber5,afterthatuserwillclickonthe
addition to get the total for both number.When the process division is successful, the
dialogpopupthetotalofbothnumberis3.


Conclusion

In conclusion, the basic calculator has been created nowadays is for ease the
user to calculate any calculation that involving numbers such as addition,subtraction,
multiplication, and division which is user can user use the calculator with touch
recognition than using the manual calculation which is using paper.Regarding from
that,this calculator are already inourmarketablewhen as we can see almost all touch
screen handphone havethese calculator.These can make usercantakeanywhereand
useeverywhereandanytime.
The benefits this invention can improve our productivity as human being to
successful in lifebecause daybydaywillbecomeout with anotherinventionsothese
will be the first enhancement for the inventor to brainstorm their idea to create a
differentideaforthefuture.

También podría gustarte