Sabtu, 22 Juli 2017

Program Android Hitung Luas Lingkaran



 Nama : JENDI DESTARI
NIM    : 2014141757
Kelas   : 06 TPLM 014

 



KODE XML (Layout) - MainActivity.xml

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity"
  tools:ignore="HardcodedText" >
  <EditText
  android:id="@+id/edJari"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentLeft="true"
  android:layout_alignParentRight="true"
  android:layout_alignParentTop="true"
  android:layout_marginTop="50dp"
  android:ems="10"
  android:hint="Jari - Jari" />
  <Button
  android:id="@+id/btHitung"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignLeft="@+id/edJari"
  android:layout_alignRight="@+id/edJari"
  android:layout_below="@+id/edJari"
  android:layout_marginTop="19dp"
  android:text="Hitung" />
  <EditText
  android:id="@+id/edLuasLingkaran"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignLeft="@+id/btHitung"
  android:layout_alignRight="@+id/btHitung"
  android:layout_below="@+id/btHitung"
  android:layout_marginTop="21dp"
  android:ems="10"
  android:hint="Luas Lingkaran" >
  <requestFocus />
    </EditText>
    <Button
      android:id="@+id/btRumus"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignLeft="@+id/edLuasLingkaran"
      android:layout_alignRight="@+id/edLuasLingkaran"
      android:layout_below="@+id/edLuasLingkaran"
      android:layout_marginTop="62dp"
      android:text="Rumus" />
    <Button
        android:id="@+id/btExit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btRumus"
        android:layout_alignRight="@+id/edLuasLingkaran"
        android:layout_below="@+id/btRumus"
        android:text="Exit" />
     </RelativeLayout>

KODE XML (Layout) - ActivityRumusLingkaran.xml

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".RumusLingkaran"
    tools:ignore="HardcodedText" >
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="21dp"
        android:layout_marginTop="36dp"
        android:text="Rumus Keliling Lingkaran"
        android:textAppearance="?android:attr/textAppearanceLarge" />
       <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="84dp"
        android:text="Luas Lingkaran = ( 22/7 ) * ( r * 2 )" />
      <Button
        android:id="@+id/btOk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="36dp"
        android:text="OK"
        android:onClick="ok"/>
       </RelativeLayout>

      KODE JAVA - MainActivity.java

        package com.luaslingkaran;
        import android.app.Activity;
        import android.content.Intent;
        import android.os.Bundle;
        import android.view.Menu;
        import android.view.View;
        import android.view.View.OnClickListener;
        import android.widget.EditText;
        public class MainActivity extends Activity implements OnClickListener{
       @Override
        protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       findViewById(R.id.btExit).setOnClickListener(this);
       findViewById(R.id.btRumus).setOnClickListener(this);
        findViewById(R.id.btHitung).setOnClickListener(this);
       }
      @Override
       public boolean onCreateOptionsMenu(Menu menu) {
       // Inflate the menu; this adds items to the action bar if it is present.
       getMenuInflater().inflate(R.menu.main, menu);
       return true;
      }
     @Override
      public void onClick(View v) {
      double r, luas;
      String luaslingkaran;
      final EditText edJari = (EditText) findViewById(R.id.edJari);
      final EditText edLuasLingkaran = (EditText) findViewById(R.id.edLuasLingkaran);
      switch (v.getId()){
       case R.id.btHitung:
       r  = Double.parseDouble(edJari.getText().toString()) ;
       luas = 3.1 * (r*r);
       luaslingkaran = String.valueOf(luas);
       break;
       case R.id.btRumus:
       Intent pindah = new Intent(this, RumusLingkaran.class);
       startActivity(pindah);
       break;
       case R.id.btExit:
       finish();
      }
   }
}
       KODE JAVA - RumusLingkaran.java

    package com.luaslingkaran;
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.View;
    public class RumusLingkaran extends Activity {
   @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rumus_lingkaran);
   }
    public void ok(View V){
    finish();
   }
   @Override
    public boolean onCreateOptionsMenu(Menu menu) {
   // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.rumus_lingkaran, menu);
    return true;
    }
}






Tidak ada komentar:

Posting Komentar

Program Android Hitung Luas Lingkaran

 Nama : JENDI DESTARI NIM    : 2014141757 Kelas   : 06 TPLM 014   KODE XML (Layout) - MainActivity.xml <RelativeLay...