Last active
July 10, 2019 16:30
-
-
Save fadjriaf/abb79f1191a99b6c7c50bbfe581c59c5 to your computer and use it in GitHub Desktop.
Hitung Luas & Keliling Lingkaran
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Source Code .xml & .java | |
Hitung Luas & Keliling Lingkaran Android Studio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" | |
tools:context=".MainActivity"> | |
<TextView | |
android:id="@+id/tv1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:text="Aplikasi Android" | |
android:layout_centerHorizontal="true" /> | |
<TextView | |
android:id="@+id/tv2" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="40dp" | |
android:text="Hitung Luas dan Keliling Lingkaran" | |
android:layout_centerHorizontal="true" /> | |
<EditText | |
android:id="@+id/masukan" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:ems="10" | |
android:hint="Masukkan Jari-Jari" | |
android:inputType="textPersonName" | |
tools:ignore="MissingConstraints" | |
android:layout_marginTop="70dp" | |
android:maxLines="2" | |
android:layout_centerHorizontal="true" /> | |
<Button | |
android:id="@+id/button" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Hitung" | |
tools:ignore="MissingConstraints" | |
android:layout_marginTop="120dp" | |
android:maxLines="2" | |
android:layout_centerHorizontal="true" /> | |
<TextView | |
android:id="@+id/hasil" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
tools:ignore="MissingConstraints" | |
android:layout_marginTop="170dp" | |
android:maxLines="2" /> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.hitunglingkaran; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.annotation.SuppressLint; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
Button button; | |
EditText masukan; | |
TextView hasil; | |
double phi = 3.14; | |
double r, luas, keliling, jari; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
button = (Button) findViewById(R.id.button); | |
masukan = (EditText) findViewById(R.id.masukan); | |
hasil = (TextView) findViewById(R.id.hasil); | |
button.setOnClickListener(new Button.OnClickListener() { | |
@SuppressLint("SetText18n") | |
@Override | |
public void onClick(View v){ | |
jari = Double.parseDouble(masukan.getText().toString()); | |
luas = phi * jari * jari; | |
keliling = 2 * phi * jari; | |
hasil.setText("Luasnya adalah : " + luas + "\nKelilingnya adalah : " + keliling); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment