Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Laporan Pemrograman Aplikasi Mobile: Oleh Reny Virgianti 1731130031 TT 3A

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

LAPORAN

PEMROGRAMAN APLIKASI MOBILE

Oleh
Reny Virgianti
1731130031
TT 3A

PROGRAM STUDI TEKNIK TELEKOMUNIKASI


JURUSAN TEKNIK ELEKTRO
POLITEKNIK NEGERI MALANG
2019
A. Tujuan
1. Mahasiswa dapat membuat Kalkuator di aplikasi android studio.
2. Mahasiswa dapat mengaplikasikan coding java di smartphone.

B. Alat dan Bahan


1. Laptop
2. Kabel usb
3. Software Android Studio
4. Smartphone (Minimal OS Ice Cream Sandwitch)

C. Proses

Buat project baru


Atur layout kalkulator seperti ini

Dan sesuaikan atribut masing-masing pallete dengan coding seperti berikut


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A90757A2"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="301dp"
android:layout_height="59dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="@string/kalkulator_biasa"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView2"
android:layout_width="119dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="24dp"
android:layout_marginTop="127dp"
android:text="@string/angka_1"
android:textSize="24sp"
android:textStyle="bold" />

<TextView
android:id="@+id/textView3"
android:layout_width="120dp"
android:layout_height="41dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="23dp"
android:layout_marginTop="190dp"
android:text="@string/angka_2"
android:textSize="24sp"
android:textStyle="bold" />

<EditText
android:id="@+id/value1"
android:layout_width="wrap_content"
android:layout_height="62dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="125dp"
android:layout_marginEnd="48dp"
android:ems="10"
android:hint="@string/masukkan_angka_1"
android:inputType="number" />

<EditText
android:id="@+id/value2"
android:layout_width="wrap_content"
android:layout_height="57dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="191dp"
android:layout_marginEnd="50dp"
android:ems="10"
android:hint="@string/masukkan_angka_2"
android:inputType="number" />

<Button
android:id="@+id/Buttontambah"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="26dp"
android:layout_marginTop="275dp"
android:text="@string/tambah" />

<Button
android:id="@+id/Buttonkurang"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="109dp"
android:layout_marginTop="276dp"
android:text="@string/kurang" />

<Button
android:id="@+id/Buttonperkali"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="276dp"
android:layout_marginEnd="137dp"
android:text="@string/kali" />

<Button
android:id="@+id/Buttonpembagi"
android:layout_width="80dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="275dp"
android:layout_marginEnd="54dp"
android:text="@string/bagi" />

<TextView
android:id="@+id/result"
android:layout_width="334dp"
android:layout_height="47dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="29dp"
android:layout_marginTop="372dp"
android:hint="@string/hasil"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>

Buka coding string dan daftarkan setiap pallete pada string

Selanjutnya buka MainActivity.java untuk mengetikkan coding seperti berikut


@Override
public void onCreate(Bundle savedInstanceState) {
final String LOG_TAG = "MainScreen";
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final EditText value1 = findViewById(R.id.value1);


final EditText value2 = findViewById(R.id.value2);
final TextView result = findViewById(R.id.result);

Button Buttontambah = findViewById(R.id.Buttontambah);


Buttontambah.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
Float val1 = Float.parseFloat(value1.getText().toString());
Float val2 = Float.parseFloat(value2.getText().toString());

Float answer = val1 + val2;


result.setText(answer.toString());
}
catch (Exception e) {
Log.e(LOG_TAG, "Failed to Add Number", e);
}
}
});

Button Buttonkurang = findViewById(R.id.Buttonkurang);


Buttonkurang.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
Float val1 = Float.parseFloat(value1.getText().toString());
Float val2 = Float.parseFloat(value2.getText().toString());

Float answer = val1 - val2;


result.setText(answer.toString());
}
catch (Exception e) {
Log.e(LOG_TAG, "Failed to Add Number", e);
}
}
});

Button Buttonperkali = findViewById(R.id.Buttonperkali);


Buttonperkali.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
Float val1 = Float.parseFloat(value1.getText().toString());
Float val2 = Float.parseFloat(value2.getText().toString());

Float answer = val1 * val2;


result.setText(answer.toString());
}
catch (Exception e) {
Log.e(LOG_TAG, "Failed to Add Number", e);
}
}
});
Button Buttonpembagi = findViewById(R.id.Buttonpembagi);
Buttonpembagi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
Float val1 = Float.parseFloat(value1.getText().toString());
Float val2 = Float.parseFloat(value2.getText().toString());

Float answer = val1 / val2;


result.setText(answer.toString());
}
catch (Exception e) {
Log.e(LOG_TAG, "Failed to Add Number", e);
}
}
});
Berikut hasil setelah di run pada device smartphone

You might also like