Skip to content

Instantly share code, notes, and snippets.

@eyp1453
Created February 12, 2018 11:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyp1453/4511b2a9fe7a6ff78d4d4e2022a4e2b2 to your computer and use it in GitHub Desktop.
Save eyp1453/4511b2a9fe7a6ff78d4d4e2022a4e2b2 to your computer and use it in GitHub Desktop.
public class MainActivity extends AppCompatActivity {
int quantity = 3; // 3den başlıyor kişi sayısı
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void submitOrder(View view){//Submit tuşuna basıldığında
CheckBox whippedCreamCheckBox = (CheckBox)findViewById(R.id.whipped_cream_checkbox);//ChechBox ın ıd sini belirtiyoruz
boolean hasWhippedCream = whippedCreamCheckBox.isChecked();// İşaretlenmişsse true, işaretlenmemişse false
EditText name = (EditText)findViewById(R.id.name_field);//Edittext Id
String isim = name.getText().toString();//Yazıyı al Stringe dönüştür
CheckBox chocalateBox = (CheckBox)findViewById(R.id.chocolate_checkbox);
boolean hasChocalateBox = chocalateBox.isChecked();
int price = calculatePrice(hasWhippedCream,hasChocalateBox);
String priceMessage = createOrderSummary(price,hasWhippedCream,hasChocalateBox,isim);
displayMessage(priceMessage);
}
private int calculatePrice(boolean addWhippedCream,boolean addChocalate){
int baseprice = 5;
if (addWhippedCream){
baseprice = baseprice + 1;
}
if (addChocalate){//
baseprice = baseprice + 2;
}
return quantity * baseprice;
}
private String createOrderSummary(int price,boolean addWhippedCream,boolean chocalateBox,String name){
String priceMessage = "Name : " + name ; //Name ve edittextte girilen ismi alcak göstercek :D
priceMessage += "\n Add whipped Cream? " + addWhippedCream;//CheckBox
priceMessage += "\n Add chocalate? " + chocalateBox;//CheckBox
priceMessage += "\n Quantity: " + quantity; //+= şu anlamda priceMessage = priceMessage + "Quantity :" + quantity;
priceMessage += "\n Total Tl : " + price;
priceMessage += "\n Thank You! ";
return priceMessage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment