Advertisement
Baru_Berbagi

pesanan.java

Oct 21st, 2020
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.91 KB | None | 0 0
  1.   package com.baruberbagi.pemesanan;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.CheckBox;
  11. import android.widget.EditText;
  12. import android.widget.TextView;
  13. import android.widget.Toast;
  14.  
  15. public class MainActivity extends AppCompatActivity {
  16.  
  17.     TextView txtHarga,txtHasil, txtJumlah;
  18.     EditText edtNama, edtAlamat, edtNohp;
  19.     CheckBox cbx_tomat, cbx_bawang;
  20.     int jumlah, total, harga=10, tomat,bawang;
  21.     String nama,alamat,noHp, statusTomat = "tidak", statusBawang= "tidak";
  22.     boolean isCbx_tomat, isCbx_bawang;
  23.     Button btnShare;
  24.  
  25.  
  26.     @Override
  27.     protected void onCreate(Bundle savedInstanceState) {
  28.         super.onCreate(savedInstanceState);
  29.         setContentView(R.layout.activity_main);
  30.  
  31.         txtJumlah = findViewById(R.id.txt_jumlah);
  32.         txtHarga = findViewById(R.id.txt_harga);
  33.         edtNama = findViewById(R.id.edt_nama);
  34.         txtHasil = findViewById(R.id.txt_hasil);
  35.         cbx_tomat = findViewById(R.id.cbx_tomat);
  36.         cbx_bawang = findViewById(R.id.cbx_bawang);
  37.  
  38.         edtAlamat = findViewById(R.id.edt_alamat);
  39.         edtNohp = findViewById(R.id.edt_nohp);
  40.  
  41.         btnShare = findViewById(R.id.btn_share);
  42.         btnShare.setOnClickListener(new View.OnClickListener() {
  43.             @Override
  44.             public void onClick(View v) {
  45.                 share();
  46.             }
  47.         });
  48.  
  49.     }
  50.     public void sambal(){
  51.         if (cbx_tomat.isChecked()){
  52.             isCbx_tomat=true;
  53.             statusTomat="Sambal Tomat";
  54.             tomat=1;
  55.         }else {
  56.             isCbx_tomat=false;
  57.             statusTomat="";
  58.             tomat=0;
  59.         }
  60.         if (cbx_bawang.isChecked()){
  61.             isCbx_bawang=true;
  62.             statusBawang="Sambal Bawang";
  63.             bawang=2;
  64.         }else {
  65.             isCbx_bawang=false;
  66.             statusBawang="";
  67.             bawang=0;
  68.         }
  69.     }
  70.     public void tambah(View view){
  71.         jumlah = jumlah + 1;
  72.         txtJumlah.setText("" + jumlah);
  73.     }
  74.     public void kurang(View view){
  75.         jumlah = jumlah - 1;
  76.         txtJumlah.setText("" + jumlah);
  77.     }
  78.     public void lihat(View view){
  79.        String nama = edtNama.getText().toString();
  80.        String alamat = edtAlamat.getText().toString();
  81.        String nohp = edtNohp.getText().toString();
  82.        int jumlah = Integer.parseInt(txtJumlah.getText().toString());
  83.        if (nama.equals("")){
  84.            edtNama.setError("Harap di isi");
  85.        }else if (alamat.equals("")){
  86.            edtAlamat.setError("Harap di isi");
  87.        }else if (nohp.equals("")){
  88.            edtNohp.setError("Harap di isi");
  89.        }
  90.        else if (jumlah < 1){
  91.            Toast.makeText(getApplicationContext(),"Pesanan minimal 1 porsi",Toast.LENGTH_SHORT).show();
  92.        }
  93.        else {
  94.            display(harga);
  95.        }
  96.     }
  97.  
  98.     public void display(int harga){
  99.  
  100.         sambal();
  101.         total = jumlah * harga;
  102.         if (isCbx_tomat){
  103.             total += (jumlah * tomat);
  104.         }
  105.         else if (isCbx_bawang) {
  106.             total += (jumlah * bawang);
  107.         }
  108.  
  109.         Log.i("harga :", "" + total);
  110.         nama = edtNama.getText().toString();
  111.         alamat = edtAlamat.getText().toString();
  112.         noHp = edtNohp.getText().toString();
  113.         txtHasil.setText("Nama : " + nama +
  114.                 "\n" + "Alamat : " + alamat+
  115.                 "\n" + "No HP/WA: " + noHp +
  116.                 "\n"+ "Pilihan Sambal : " +statusTomat +
  117.                 "\n" + statusBawang +
  118.                         "\n" + "Jumlah : " + jumlah + "Porsi" +
  119.                  "\nTerimakasih");
  120.         txtHarga.setText("Total Harga : Rp." + total + "000");
  121.     }
  122.     public void share() {
  123.         String hasil = txtHasil.getText().toString();
  124.         if (hasil.equals("")) {
  125.             Toast.makeText(getApplicationContext(), "harap tekan tombol lihat terlebih dahulu sebelum melakukan pengorderan", Toast.LENGTH_SHORT).show();
  126.         } else {
  127.             Intent intent = new Intent(Intent.ACTION_SEND);
  128.             intent.setType("text/plain");
  129.             intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"pendapatan.tia@gmail.com"});
  130.             intent.putExtra(Intent.EXTRA_SUBJECT, "Pesanan Ayam Geprek");
  131.             intent.putExtra(Intent.EXTRA_TEXT,
  132.                     "Nama : " + nama + "\n" + "Alamat :" + alamat +
  133.                             "\n" + "No HP/WA: " + noHp +
  134.                             "\n" + "Pilhan Sambal : " + statusTomat +
  135.                             "\n" + statusBawang +
  136.                             "\n" + "Jumlah : " + jumlah + "Porsi" +
  137.                             "\n" + " Total Harga : Rp." + total + "000" +
  138.                             "\n" + "Terimakasih");
  139.  
  140.             startActivity(Intent.createChooser(intent, "Send Email"));
  141.         }
  142.     }
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement