Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.kedaiumis;
- import android.os.Bundle;
- import android.support.v7.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;
- /**
- * This app displays an order form to order coffee.
- */
- public class SecondActivity extends AppCompatActivity {
- int quantity=0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.second_main);
- }
- 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=0;
- if(addwhipedcream){
- harga=13000;//harga tambahan toping
- }
- if (addchocolate){
- harga=15000;
- }
- return quantity * harga;
- }
- private String createOrderSummary(int price, String name, boolean addChocolate, boolean addWhippedCream) {//hasil pemesanan
- String pricemessage=" Nama = "+name;
- if (addChocolate)
- pricemessage+="\n Roti";
- else if (addWhippedCream)
- pricemessage+="\n Ice Cream";
- pricemessage+="\n Jumlah Pemesanan =" +quantity;
- pricemessage+="\n Total = Rp " +price;
- pricemessage+="\n Terimakasih";
- 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));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement