Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package com.example.restoalan;
  2.  
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import androidx.appcompat.app.AppCompatActivity;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.widget.CheckBox;
  9. import android.widget.EditText;
  10. import android.widget.TextView;
  11. import android.widget.Toast;
  12.  
  13. import java.text.NumberFormat;
  14.  
  15. import static android.R.string.no;
  16. import static android.os.Build.VERSION_CODES.N;
  17.  
  18. import android.os.Bundle;
  19.  
  20.  
  21. public class pesananActivity extends AppCompatActivity {
  22.  
  23.     int quantity=0;
  24.     @Override
  25.     protected void onCreate(Bundle savedInstanceState) {
  26.         super.onCreate(savedInstanceState);
  27.         setContentView(R.layout.activity_pesanan);
  28.     }
  29.     public void increment(View view){//perintah tombol tambah
  30.         if(quantity==100){
  31.             Toast.makeText(this,"pesanan maximal 100",Toast.LENGTH_SHORT).show();
  32.             return;
  33.         }
  34.         quantity = quantity+1 ;
  35.         display(quantity);
  36.     }
  37.     public void decrement(View view){//perintah tombol tambah
  38.             if (quantity==1){
  39.                 Toast.makeText(this,"pesanan minimal 1",Toast.LENGTH_SHORT).show();
  40.                 return;
  41.             }
  42.             quantity = quantity -1;
  43.             display(quantity);
  44.     }
  45.  
  46.  
  47.     public void Submitorder(View view) {
  48.         EditText nameEditText=(EditText)findViewById(R.id.edt_name);
  49.         String name=nameEditText.getText().toString();
  50.         Log.v("MainActivity","Nama:"+name);
  51.  
  52.         CheckBox whippedcreamChekBox= (CheckBox) findViewById(R.id.WhippedCream_checkbox);
  53.         boolean haswhippedcream=whippedcreamChekBox.isChecked();//mengidentifikasi check
  54.         Log.v("MainActivity","has whippedcream:"+haswhippedcream);
  55.  
  56.         CheckBox chocolateChekBox= (CheckBox) findViewById(R.id.Chocolate_checkbox);
  57.         boolean haschocolate=chocolateChekBox.isChecked();//mengidentifikasi check
  58.         Log.v("MainActivity","has whippedcream:"+haschocolate);
  59.  
  60.         int price=calculateprice(haswhippedcream,haschocolate);//memanggil method jumlah harga
  61.         String pricemessage=createOrderSummary(price,name,haswhippedcream,haschocolate);
  62.  
  63.  
  64.         displayMessage(pricemessage);
  65.  
  66.     }
  67.     private int calculateprice(boolean addwhipedcream,boolean addchocolate){//jumlah pesanan * harga
  68.         int harga=5000;
  69.  
  70.         if(addwhipedcream){
  71.             harga=harga+1000;//harga tambahan toping
  72.         }
  73.  
  74.         if (addchocolate){
  75.             harga=harga+2000;
  76.         }
  77.  
  78.         return quantity * harga;
  79.     }
  80.     private String createOrderSummary(int price, String name, boolean addChocolate, boolean addWhippedCream) {//hasil pemesanan
  81.         String pricemessage=" Nama ="+name;
  82.         pricemessage+="\n add Whipped Cream?"+addWhippedCream;
  83.         pricemessage+="\n add Chocolate?"+addChocolate;
  84.         pricemessage+="\n quantity"+quantity;
  85.         pricemessage+="\n Total Rp"+price;
  86.         pricemessage+="\n Thankyou";
  87.         return  pricemessage;
  88.     }
  89.  
  90.     //method ini untuk mencetak hasil perintah yang di tampilkan dengan inisial quantity_textview di textview 0
  91.     private void displayMessage(String message) {
  92.         TextView priceTextView = (TextView) findViewById(R.id.price_textview);
  93.         priceTextView.setText(message);
  94.     }
  95.     private void display(int number) {
  96.         TextView quantityTextView = (TextView) findViewById(R.id.quantity_textview);
  97.         quantityTextView.setText("" + number);
  98.     }
  99.     private void displayPrice(int number) {
  100.         TextView priceTextView = (TextView) findViewById(R.id.price_textview);
  101.         priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
  102.     }
  103.  
  104. }