Advertisement
adesuryadi_

KalkulatorZakat

May 15th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:layout_marginStart="8dp"
  8. android:layout_marginTop="8dp"
  9. android:layout_marginEnd="8dp"
  10. android:layout_marginBottom="8dp"
  11. android:orientation="vertical"
  12. tools:context=".MainActivity">
  13.  
  14. <EditText
  15. android:id="@+id/gaji"
  16. android:layout_width="250dp"
  17. android:layout_height="wrap_content"
  18. android:hint="Penghasilan/Gaji per Bulan" />
  19.  
  20. <EditText
  21. android:id="@+id/lain"
  22. android:layout_width="250dp"
  23. android:layout_height="wrap_content"
  24. android:hint="Penghasilan lainnya per Bulan" />
  25.  
  26. <EditText
  27. android:id="@+id/hutang"
  28. android:layout_width="250dp"
  29. android:layout_height="wrap_content"
  30. android:hint="Cicilan/Hutang per Bulan" />
  31.  
  32. <EditText
  33. android:id="@+id/beras"
  34. android:layout_width="250dp"
  35. android:layout_height="wrap_content"
  36. android:layout_marginBottom="20dp"
  37. android:hint="Harga beras saat ini" />
  38.  
  39. <Button
  40. android:layout_width="wrap_content"
  41. android:layout_height="wrap_content"
  42. android:layout_marginTop="10dp"
  43. android:layout_marginBottom="20dp"
  44. android:onClick="hitung"
  45. android:text="Hitung" />
  46.  
  47. <TextView
  48. android:layout_width="wrap_content"
  49. android:layout_height="wrap_content"
  50. android:layout_marginBottom="4dp"
  51. android:text="Total Pendapatan"
  52. android:textSize="18dp" />
  53. I
  54. <TextView
  55. android:id="@+id/pendapatan"
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:layout_marginBottom="18dp"
  59. android:text="0"
  60. android:textSize="18dp" />
  61.  
  62. <TextView
  63. android:layout_width="wrap_content"
  64. android:layout_height="wrap_content"
  65. android:layout_marginBottom="4dp"
  66. android:text="Nishab Zakat"
  67. android:textSize="18dp" />
  68.  
  69. I
  70.  
  71. <TextView
  72. android:id="@+id/nishab"
  73. android:layout_width="wrap_content"
  74. android:layout_height="wrap_content"
  75. android:layout_marginBottom="18dp"
  76. android:text="0"
  77. android:textSize="18dp" />
  78.  
  79. <TextView
  80. android:layout_width="wrap_content"
  81. android:layout_height="wrap_content"
  82. android:layout_marginBottom="4dp"
  83. android:text="Zakat yang harus dikeluarkan /bulan"
  84. android:textSize="18dp" />
  85.  
  86. <TextView
  87. android:id="@+id/total"
  88. android:layout_width="wrap_content"
  89. android:layout_height="wrap_content"
  90. android:text="0"
  91. android:textSize="24dp" />
  92. </LinearLayout>
  93.  
  94.  
  95. public class MainActivity extends AppCompatActivity {
  96.  
  97. EditText edGaji, edLain, edHutang, edBeras;
  98. TextView tvNishab, tvTotal, tvPendapatan;
  99.  
  100. @Override
  101. protected void onCreate(Bundle savedInstanceState) {
  102. super.onCreate(savedInstanceState);
  103. setContentView(R.layout.activity_main);
  104. edGaji = findViewById(R.id.gaji);
  105. edLain = findViewById(R.id.lain);
  106. edHutang = findViewById(R.id.hutang);
  107. tvPendapatan = findViewById(R.id.pendapatan);
  108. edBeras = findViewById(R.id.beras);
  109. tvNishab = findViewById(R.id.nishab);
  110. tvTotal = findViewById(R.id.total);
  111. }
  112.  
  113. public void hitung(View view) {
  114. double vGaji, vLain, vHutang, vZakat,
  115. vBeras, vHasil, vNishab;
  116. vGaji = Double.parseDouble(
  117. edGaji.getText().toString());
  118. vLain = Double.parseDouble(
  119. edLain.getText().toString());
  120. vHutang = Double.parseDouble(
  121. edHutang.getText().toString());
  122. vBeras = Double.parseDouble(
  123. edBeras.getText().toString());
  124.  
  125. vHasil = vGaji + vLain - vHutang;
  126. vNishab = 522 * vBeras;
  127.  
  128. vZakat = vHasil * 0.025;
  129.  
  130. tvPendapatan.setText(
  131. Double.toString(vHasil));
  132. tvNishab.setText(
  133. Double.toString(vNishab));
  134.  
  135. if(vHasil > vNishab){
  136. tvTotal.setText(
  137. Double.toString(vZakat));
  138. }else{
  139. tvTotal.setText(
  140. "Anda Tidak Wajib Membayar" +
  141. "Zakat");
  142. }
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement