Created
February 12, 2018 11:15
-
-
Save eyp1453/4511b2a9fe7a6ff78d4d4e2022a4e2b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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