Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.baruberbagi.pemesanan;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- TextView txtHarga,txtHasil, txtJumlah;
- EditText edtNama, edtAlamat, edtNohp;
- CheckBox cbx_tomat, cbx_bawang;
- int jumlah, total, harga=10, tomat,bawang;
- String nama,alamat,noHp, statusTomat = "tidak", statusBawang= "tidak";
- boolean isCbx_tomat, isCbx_bawang;
- Button btnShare;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- txtJumlah = findViewById(R.id.txt_jumlah);
- txtHarga = findViewById(R.id.txt_harga);
- edtNama = findViewById(R.id.edt_nama);
- txtHasil = findViewById(R.id.txt_hasil);
- cbx_tomat = findViewById(R.id.cbx_tomat);
- cbx_bawang = findViewById(R.id.cbx_bawang);
- edtAlamat = findViewById(R.id.edt_alamat);
- edtNohp = findViewById(R.id.edt_nohp);
- btnShare = findViewById(R.id.btn_share);
- btnShare.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- share();
- }
- });
- }
- public void sambal(){
- if (cbx_tomat.isChecked()){
- isCbx_tomat=true;
- statusTomat="Sambal Tomat";
- tomat=1;
- }else {
- isCbx_tomat=false;
- statusTomat="";
- tomat=0;
- }
- if (cbx_bawang.isChecked()){
- isCbx_bawang=true;
- statusBawang="Sambal Bawang";
- bawang=2;
- }else {
- isCbx_bawang=false;
- statusBawang="";
- bawang=0;
- }
- }
- public void tambah(View view){
- jumlah = jumlah + 1;
- txtJumlah.setText("" + jumlah);
- }
- public void kurang(View view){
- jumlah = jumlah - 1;
- txtJumlah.setText("" + jumlah);
- }
- public void lihat(View view){
- String nama = edtNama.getText().toString();
- String alamat = edtAlamat.getText().toString();
- String nohp = edtNohp.getText().toString();
- int jumlah = Integer.parseInt(txtJumlah.getText().toString());
- if (nama.equals("")){
- edtNama.setError("Harap di isi");
- }else if (alamat.equals("")){
- edtAlamat.setError("Harap di isi");
- }else if (nohp.equals("")){
- edtNohp.setError("Harap di isi");
- }
- else if (jumlah < 1){
- Toast.makeText(getApplicationContext(),"Pesanan minimal 1 porsi",Toast.LENGTH_SHORT).show();
- }
- else {
- display(harga);
- }
- }
- public void display(int harga){
- sambal();
- total = jumlah * harga;
- if (isCbx_tomat){
- total += (jumlah * tomat);
- }
- else if (isCbx_bawang) {
- total += (jumlah * bawang);
- }
- Log.i("harga :", "" + total);
- nama = edtNama.getText().toString();
- alamat = edtAlamat.getText().toString();
- noHp = edtNohp.getText().toString();
- txtHasil.setText("Nama : " + nama +
- "\n" + "Alamat : " + alamat+
- "\n" + "No HP/WA: " + noHp +
- "\n"+ "Pilihan Sambal : " +statusTomat +
- "\n" + statusBawang +
- "\n" + "Jumlah : " + jumlah + "Porsi" +
- "\nTerimakasih");
- txtHarga.setText("Total Harga : Rp." + total + "000");
- }
- public void share() {
- String hasil = txtHasil.getText().toString();
- if (hasil.equals("")) {
- Toast.makeText(getApplicationContext(), "harap tekan tombol lihat terlebih dahulu sebelum melakukan pengorderan", Toast.LENGTH_SHORT).show();
- } else {
- Intent intent = new Intent(Intent.ACTION_SEND);
- intent.setType("text/plain");
- intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"pendapatan.tia@gmail.com"});
- intent.putExtra(Intent.EXTRA_SUBJECT, "Pesanan Ayam Geprek");
- intent.putExtra(Intent.EXTRA_TEXT,
- "Nama : " + nama + "\n" + "Alamat :" + alamat +
- "\n" + "No HP/WA: " + noHp +
- "\n" + "Pilhan Sambal : " + statusTomat +
- "\n" + statusBawang +
- "\n" + "Jumlah : " + jumlah + "Porsi" +
- "\n" + " Total Harga : Rp." + total + "000" +
- "\n" + "Terimakasih");
- startActivity(Intent.createChooser(intent, "Send Email"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement