0% found this document useful (0 votes)
6 views6 pages

Tugas 1 TMLN

This document outlines a mobile programming practical assignment by Paulus Apriliano Crespo at Universitas Dipa Makassar. It includes XML layout code for a simple calculator app with input fields for two values and buttons for addition, subtraction, multiplication, and division. The Java code implements the functionality to perform calculations based on user input and display the result.

Uploaded by

Crespo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Tugas 1 TMLN

This document outlines a mobile programming practical assignment by Paulus Apriliano Crespo at Universitas Dipa Makassar. It includes XML layout code for a simple calculator app with input fields for two values and buttons for addition, subtraction, multiplication, and division. The Java code implements the functionality to perform calculations based on user input and display the result.

Uploaded by

Crespo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

TUGAS 1

Praktikum Pemerogramman Mobile

Paulus Apriliano Crespo


222144
4TLMN-D

UNIVERSITAS DIPA MAKASSAR


TEKNIK INFORMATIKA
SEMESTER GENAP 2023/2024
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="60dp">

<!-- Input Fields -->


<LinearLayout
android:layout_width="match_parent"
android:layout_height="252dp"
android:layout_marginBottom="16dp"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15px"
android:text="Nilai 1"
android:textAlignment="center"
android:textSize="60px" />

<EditText
android:id="@+id/nilai1EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border"
android:padding="15px" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="15px"
android:text="Nilai 2"
android:textAlignment="center"
android:textSize="60px" />

<EditText
android:id="@+id/nilai2EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20px"
android:background="@drawable/border"
android:padding="15px" />

<TextView
android:id="@+id/hasilTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="@drawable/border"
android:padding="15px"
android:text="Hasil"
android:textAlignment="center"
android:textSize="55px"
android:textStyle="bold" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="50px"

>

<Button

android:id="@+id/tambahButton"
android:layout_width="345px"
android:layout_height="wrap_content"
android:layout_marginRight="50px"
android:background="@drawable/border_radius"
android:text="Hasil +" />

<Button

android:id="@+id/kurangButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border_radius"
android:text="Hasil -" />
</LinearLayout>

<LinearLayout

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/bagiButton"
android:layout_width="345px"
android:layout_height="wrap_content"
android:layout_marginRight="50px"
android:background="@drawable/border_radius"
android:text="Hasil :" />

<Button
android:id="@+id/kaliButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border_radius"
android:text="Hasil x" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="[Link]
android:shape="rectangle">
<solid android:color="@android:color/white" />
<stroke
android:width="1dp"
android:color="@android:color/black" />

</shape>

<?xml version="1.0" encoding="utf-8"?>


<shape
xmlns:android="[Link]
android:shape="rectangle">
<corners android:radius="8dp"/>
<solid android:color="@color/dark_l"/>
<stroke android:color="@color/lilac"
android:width="2dp"/>
</shape>

<?xml version="1.0" encoding="utf-8"?>


<resources>
<color name="black">#000000</color>
<color name="white">#FFFFFF</color>
<color name="lilac">#7E40EC</color>
<color name="dark_l">#9F87CC</color>
</resources>

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


private EditText nilai1EditText, nilai2EditText;
private TextView hasilTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

nilai1EditText = findViewById([Link].nilai1EditText);
nilai2EditText = findViewById([Link].nilai2EditText);
hasilTextView = findViewById([Link]);

Button tambahButton = findViewById([Link]);


Button kurangButton = findViewById([Link]);
Button bagiButton = findViewById([Link]);
Button kaliButton = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
hitung('+');
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
hitung('-');
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
hitung('/');
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
hitung('*');
}
});
}

private void hitung(char operator) {


double nilai1 =
[Link]([Link]().toString());
double nilai2 =
[Link]([Link]().toString());
double hasil = 0;

switch (operator) {
case '+':
hasil = nilai1 + nilai2;
break;
case '-':
hasil = nilai1 - nilai2;
break;
case '/':
if (nilai2 != 0) {
hasil = nilai1 / nilai2;
} else {
[Link]("Pembagian Dengan Nol");
return;
}
break;
case '*':
hasil = nilai1 * nilai2;
break;
}

[Link]([Link](hasil));
}
}

You might also like