Guest User

Untitled

a guest
Jun 25th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. <string name="total_coffee_cost">Hi, %1$s. You ordered %2$d cups of coffee. nPrepare to pay $%3$d. nThank you!</string>
  2. <string name="total_coffee_cost_whipped_cream">Hi, %1$s. You ordered %2$d cups of coffee, whipped cream will be added. nPrepare to pay $%3$d. nThank you!</string>
  3. <string name="total_coffee_cost_chocolate">Hi, %1$s. You ordered %2$d cups of coffee, chocolate will be added. nPrepare to pay $%3$d. nThank you!</string>
  4. <string name="total_coffee_cost_cream_chocolate">Hi, %1$s. You ordered %2$d cups of coffee, whipped cream and chocolate will be added. nPrepare to pay $%3$d. nThank you!</string>
  5. <string name="total_coffee_cost_one">Hi, %1$s. You ordered %2$d cup of coffee. nPrepare to pay $%3$d. nThank you!</string>
  6. <string name="total_coffee_cost_one_whipped_cream">Hi, %1$s. You ordered %2$d cup of coffee, whipped cream will be added. nPrepare to pay $%3$d. nThank you!</string>
  7. <string name="total_coffee_cost_one_chocolate">Hi, %1$s. You ordered %2$d cup of coffee, chocolate will be added. nPrepare to pay $%3$d. nThank you!</string>
  8. <string name="total_coffee_cost_one_cream_chocolate">Hi, %1$s. You ordered %2$d cup of coffee, whipped cream and chocolate will be added. nPrepare to pay $%3$d. nThank you!</string>
  9. <string name="total_coffee_cost_zero">Hi, %1$s. You have not ordered any cup of coffee. nTry to choose again. nThank you!</string>
  10.  
  11. private TextView createOrderSummary(View view){
  12. EditText nameField = findViewById(R.id.name_field);
  13. String name = nameField.getText().toString();
  14.  
  15. CheckBox whippedCreamCheckBox = findViewById(R.id.whipped_cream_checkbox);
  16. hasWhippedCream = whippedCreamCheckBox.isChecked();
  17.  
  18. CheckBox chocolateCheckBox = findViewById(R.id.chocolate_checkbox);
  19. hasChocolate = chocolateCheckBox.isChecked();
  20.  
  21. TextView priceMessage = findViewById(R.id.price_text_view);
  22. if (numberOfCoffees == 0)
  23. priceMessage.setText(getString(R.string.total_coffee_cost_zero, name));
  24. else if ((numberOfCoffees == 1) && (!hasWhippedCream) && (!hasChocolate))
  25. priceMessage.setText(getString(R.string.total_coffee_cost_one,name, numberOfCoffees, numberOfCoffees * priceOfCup));
  26. else if ((numberOfCoffees == 1) && (hasWhippedCream) && (!hasChocolate))
  27. priceMessage.setText(getString(R.string.total_coffee_cost_one_whipped_cream, name, numberOfCoffees, numberOfCoffees * priceOfCup));
  28. else if ((numberOfCoffees == 1) && (!hasWhippedCream) && (hasChocolate))
  29. priceMessage.setText(getString(R.string.total_coffee_cost_one_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup));
  30. else if ((numberOfCoffees == 1) && (hasWhippedCream) && (hasChocolate))
  31. priceMessage.setText(getString(R.string.total_coffee_cost_one_cream_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup));
  32. else if ((numberOfCoffees > 1) && (!hasWhippedCream) && (!hasChocolate))
  33. priceMessage.setText(getString(R.string.total_coffee_cost, name, numberOfCoffees, numberOfCoffees * priceOfCup));
  34. else if ((numberOfCoffees > 1) && (hasWhippedCream) && (!hasChocolate))
  35. priceMessage.setText(getString(R.string.total_coffee_cost_whipped_cream, name, numberOfCoffees, numberOfCoffees * priceOfCup));
  36. else if ((numberOfCoffees > 1) && (!hasWhippedCream) && (hasChocolate))
  37. priceMessage.setText(getString(R.string.total_coffee_cost_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup));
  38. else if ((numberOfCoffees > 1) && (hasWhippedCream) && (hasChocolate))
  39. priceMessage.setText(getString(R.string.total_coffee_cost_cream_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup));
  40. return priceMessage;
  41. }
  42.  
  43. <string name="total_coffee_cost">Hi, %1$s! You ordered %2$d cups of coffee. nPrepare to pay $%3$d. nThank you!</string>
  44.  
  45. private TextView createOrderSummary(View view){
  46. EditText nameField = findViewById(R.id.name_field);
  47. String name = nameField.getText().toString();
  48.  
  49. CheckBox whippedCreamCheckBox = findViewById(R.id.whipped_cream_checkbox);
  50. hasWhippedCream = whippedCreamCheckBox.isChecked();
  51.  
  52. CheckBox chocolateCheckBox = findViewById(R.id.chocolate_checkbox);
  53. hasChocolate = chocolateCheckBox.isChecked();
  54.  
  55. TextView priceMessage = findViewById(R.id.price_text_view);
  56.  
  57. if (numberOfCoffees == 0) {
  58. textString = getString(R.string.total_coffee_cost_zero, name);
  59. priceMessage.setText(textString);
  60. }
  61. else if ((numberOfCoffees == 1) && (!hasWhippedCream) && (!hasChocolate)) {
  62. textString = getString(R.string.total_coffee_cost_one, name, numberOfCoffees, numberOfCoffees * priceOfCup);
  63. priceMessage.setText(textString);
  64. }
  65. else if ((numberOfCoffees == 1) && (hasWhippedCream) && (!hasChocolate)) {
  66. textString = getString(R.string.total_coffee_cost_one_whipped_cream, name, numberOfCoffees, numberOfCoffees * priceOfCup);
  67. priceMessage.setText(textString);
  68. }
  69. else if ((numberOfCoffees == 1) && (!hasWhippedCream) && (hasChocolate)) {
  70. textString = getString(R.string.total_coffee_cost_one_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup);
  71. priceMessage.setText(textString);
  72. }
  73. else if ((numberOfCoffees == 1) && (hasWhippedCream) && (hasChocolate)) {
  74. textString = getString(R.string.total_coffee_cost_one_cream_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup);
  75. priceMessage.setText(textString);
  76. }
  77. else if ((numberOfCoffees > 1) && (!hasWhippedCream) && (!hasChocolate)) {
  78. textString = getString(R.string.total_coffee_cost, name, numberOfCoffees, numberOfCoffees * priceOfCup);
  79. priceMessage.setText(textString);
  80. }
  81. else if ((numberOfCoffees > 1) && (hasWhippedCream) && (!hasChocolate)) {
  82. textString = getString(R.string.total_coffee_cost_whipped_cream, name, numberOfCoffees, numberOfCoffees * priceOfCup);
  83. priceMessage.setText(textString);
  84. }
  85. else if ((numberOfCoffees > 1) && (!hasWhippedCream) && (hasChocolate)) {
  86. textString = getString(R.string.total_coffee_cost_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup);
  87. priceMessage.setText(textString);
  88. }
  89. else if ((numberOfCoffees > 1) && (hasWhippedCream) && (hasChocolate)) {
  90. textString = getString(R.string.total_coffee_cost_cream_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup);
  91. priceMessage.setText(textString);
  92. }
  93.  
  94. return priceMessage;
  95. }
Add Comment
Please, Sign In to add comment