Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <string name="total_coffee_cost">Hi, %1$s. You ordered %2$d cups of coffee. nPrepare to pay $%3$d. nThank you!</string>
- <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>
- <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>
- <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>
- <string name="total_coffee_cost_one">Hi, %1$s. You ordered %2$d cup of coffee. nPrepare to pay $%3$d. nThank you!</string>
- <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>
- <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>
- <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>
- <string name="total_coffee_cost_zero">Hi, %1$s. You have not ordered any cup of coffee. nTry to choose again. nThank you!</string>
- private TextView createOrderSummary(View view){
- EditText nameField = findViewById(R.id.name_field);
- String name = nameField.getText().toString();
- CheckBox whippedCreamCheckBox = findViewById(R.id.whipped_cream_checkbox);
- hasWhippedCream = whippedCreamCheckBox.isChecked();
- CheckBox chocolateCheckBox = findViewById(R.id.chocolate_checkbox);
- hasChocolate = chocolateCheckBox.isChecked();
- TextView priceMessage = findViewById(R.id.price_text_view);
- if (numberOfCoffees == 0)
- priceMessage.setText(getString(R.string.total_coffee_cost_zero, name));
- else if ((numberOfCoffees == 1) && (!hasWhippedCream) && (!hasChocolate))
- priceMessage.setText(getString(R.string.total_coffee_cost_one,name, numberOfCoffees, numberOfCoffees * priceOfCup));
- else if ((numberOfCoffees == 1) && (hasWhippedCream) && (!hasChocolate))
- priceMessage.setText(getString(R.string.total_coffee_cost_one_whipped_cream, name, numberOfCoffees, numberOfCoffees * priceOfCup));
- else if ((numberOfCoffees == 1) && (!hasWhippedCream) && (hasChocolate))
- priceMessage.setText(getString(R.string.total_coffee_cost_one_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup));
- else if ((numberOfCoffees == 1) && (hasWhippedCream) && (hasChocolate))
- priceMessage.setText(getString(R.string.total_coffee_cost_one_cream_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup));
- else if ((numberOfCoffees > 1) && (!hasWhippedCream) && (!hasChocolate))
- priceMessage.setText(getString(R.string.total_coffee_cost, name, numberOfCoffees, numberOfCoffees * priceOfCup));
- else if ((numberOfCoffees > 1) && (hasWhippedCream) && (!hasChocolate))
- priceMessage.setText(getString(R.string.total_coffee_cost_whipped_cream, name, numberOfCoffees, numberOfCoffees * priceOfCup));
- else if ((numberOfCoffees > 1) && (!hasWhippedCream) && (hasChocolate))
- priceMessage.setText(getString(R.string.total_coffee_cost_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup));
- else if ((numberOfCoffees > 1) && (hasWhippedCream) && (hasChocolate))
- priceMessage.setText(getString(R.string.total_coffee_cost_cream_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup));
- return priceMessage;
- }
- <string name="total_coffee_cost">Hi, %1$s! You ordered %2$d cups of coffee. nPrepare to pay $%3$d. nThank you!</string>
- private TextView createOrderSummary(View view){
- EditText nameField = findViewById(R.id.name_field);
- String name = nameField.getText().toString();
- CheckBox whippedCreamCheckBox = findViewById(R.id.whipped_cream_checkbox);
- hasWhippedCream = whippedCreamCheckBox.isChecked();
- CheckBox chocolateCheckBox = findViewById(R.id.chocolate_checkbox);
- hasChocolate = chocolateCheckBox.isChecked();
- TextView priceMessage = findViewById(R.id.price_text_view);
- if (numberOfCoffees == 0) {
- textString = getString(R.string.total_coffee_cost_zero, name);
- priceMessage.setText(textString);
- }
- else if ((numberOfCoffees == 1) && (!hasWhippedCream) && (!hasChocolate)) {
- textString = getString(R.string.total_coffee_cost_one, name, numberOfCoffees, numberOfCoffees * priceOfCup);
- priceMessage.setText(textString);
- }
- else if ((numberOfCoffees == 1) && (hasWhippedCream) && (!hasChocolate)) {
- textString = getString(R.string.total_coffee_cost_one_whipped_cream, name, numberOfCoffees, numberOfCoffees * priceOfCup);
- priceMessage.setText(textString);
- }
- else if ((numberOfCoffees == 1) && (!hasWhippedCream) && (hasChocolate)) {
- textString = getString(R.string.total_coffee_cost_one_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup);
- priceMessage.setText(textString);
- }
- else if ((numberOfCoffees == 1) && (hasWhippedCream) && (hasChocolate)) {
- textString = getString(R.string.total_coffee_cost_one_cream_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup);
- priceMessage.setText(textString);
- }
- else if ((numberOfCoffees > 1) && (!hasWhippedCream) && (!hasChocolate)) {
- textString = getString(R.string.total_coffee_cost, name, numberOfCoffees, numberOfCoffees * priceOfCup);
- priceMessage.setText(textString);
- }
- else if ((numberOfCoffees > 1) && (hasWhippedCream) && (!hasChocolate)) {
- textString = getString(R.string.total_coffee_cost_whipped_cream, name, numberOfCoffees, numberOfCoffees * priceOfCup);
- priceMessage.setText(textString);
- }
- else if ((numberOfCoffees > 1) && (!hasWhippedCream) && (hasChocolate)) {
- textString = getString(R.string.total_coffee_cost_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup);
- priceMessage.setText(textString);
- }
- else if ((numberOfCoffees > 1) && (hasWhippedCream) && (hasChocolate)) {
- textString = getString(R.string.total_coffee_cost_cream_chocolate, name, numberOfCoffees, numberOfCoffees * priceOfCup);
- priceMessage.setText(textString);
- }
- return priceMessage;
- }
Add Comment
Please, Sign In to add comment