package com.example.restoalan;
import android.content.Intent;
import android.net.Uri;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.text.NumberFormat;
import static android.R.string.no;
import static android.os.Build.VERSION_CODES.N;
import android.os.Bundle;
public class pesananActivity extends AppCompatActivity {
int quantity=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pesanan);
}
public void increment(View view){//perintah tombol tambah
if(quantity==100){
Toast.makeText(this,"pesanan maximal 100",Toast.LENGTH_SHORT).show();
return;
}
quantity = quantity+1 ;
display(quantity);
}
public void decrement(View view){//perintah tombol tambah
if (quantity==1){
Toast.makeText(this,"pesanan minimal 1",Toast.LENGTH_SHORT).show();
return;
}
quantity = quantity -1;
display(quantity);
}
public void Submitorder(View view) {
EditText nameEditText=(EditText)findViewById(R.id.edt_name);
String name=nameEditText.getText().toString();
Log.v("MainActivity","Nama:"+name);
CheckBox whippedcreamChekBox= (CheckBox) findViewById(R.id.WhippedCream_checkbox);
boolean haswhippedcream=whippedcreamChekBox.isChecked();//mengidentifikasi check
Log.v("MainActivity","has whippedcream:"+haswhippedcream);
CheckBox chocolateChekBox= (CheckBox) findViewById(R.id.Chocolate_checkbox);
boolean haschocolate=chocolateChekBox.isChecked();//mengidentifikasi check
Log.v("MainActivity","has whippedcream:"+haschocolate);
int price=calculateprice(haswhippedcream,haschocolate);//memanggil method jumlah harga
String pricemessage=createOrderSummary(price,name,haswhippedcream,haschocolate);
displayMessage(pricemessage);
}
private int calculateprice(boolean addwhipedcream,boolean addchocolate){//jumlah pesanan * harga
int harga=5000;
if(addwhipedcream){
harga=harga+1000;//harga tambahan toping
}
if (addchocolate){
harga=harga+2000;
}
return quantity * harga;
}
private String createOrderSummary(int price, String name, boolean addChocolate, boolean addWhippedCream) {//hasil pemesanan
String pricemessage=" Nama ="+name;
pricemessage+="\n add Whipped Cream?"+addWhippedCream;
pricemessage+="\n add Chocolate?"+addChocolate;
pricemessage+="\n quantity"+quantity;
pricemessage+="\n Total Rp"+price;
pricemessage+="\n Thankyou";
return pricemessage;
}
//method ini untuk mencetak hasil perintah yang di tampilkan dengan inisial quantity_textview di textview 0
private void displayMessage(String message) {
TextView priceTextView = (TextView) findViewById(R.id.price_textview);
priceTextView.setText(message);
}
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_textview);
quantityTextView.setText("" + number);
}
private void displayPrice(int number) {
TextView priceTextView = (TextView) findViewById(R.id.price_textview);
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
}
}