Guest User

Untitled

a guest
Sep 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. package com.example.android.justjava;
  2.  
  3. /**
  4. * IMPORTANT: Make sure you are using the correct package name.
  5. * This example uses the package name:
  6. * package com.example.android.justjava
  7. * If you get an error when copying this code into Android studio, update it to match teh package name found
  8. * in the project's AndroidManifest.xml file.
  9. **/
  10.  
  11.  
  12.  
  13.  
  14. import android.os.Bundle;
  15. import android.support.v7.app.AppCompatActivity;
  16. import android.view.View;
  17. import android.widget.TextView;
  18.  
  19. import java.text.NumberFormat;
  20.  
  21. /**
  22. * This app displays an order form to order coffee.
  23. */
  24. public class MainActivity extends AppCompatActivity {
  25. int quantity=0;
  26. @Override
  27. protected void onCreate(Bundle savedInstanceState) {
  28. super.onCreate(savedInstanceState);
  29. setContentView(R.layout.activity_main);
  30. }
  31.  
  32. /**
  33. * This method is called when the order button is clicked.
  34. */
  35. public void submitOrder(View view) {
  36. int price = calculatePrice();
  37. String orderSummary = createOrderSummary(price);
  38. // String priceMessage = "Total: $"+price;
  39. // priceMessage = priceMessage + "\nThank you!";
  40. // displayMessage (priceMessage);
  41. displayMessage(orderSummary);
  42. }
  43.  
  44. private String createOrderSummary(int price) {
  45. String message= "Name: Kaptain kunal " +"\n" +"Quantity: " + quantity + "\n" + "Total: $" + price +"\n" + "Thank you!";
  46. return message;
  47. }
  48.  
  49. /**
  50. * Calculates the price of the order.
  51. *
  52. * @param quantity is the number of cups of coffee ordered
  53. */
  54. private int calculatePrice() {
  55. int price = quantity * 5;
  56. return price;
  57. }
  58.  
  59. private int calculatePrice(int quantity, int pricePerCoffee) {
  60. int price = quantity * pricePerCoffee;
  61. return price;
  62. }
  63.  
  64. private int calculatePrice(int quantity) {
  65. int price = quantity * 5;
  66. return price;
  67. }
  68.  
  69. /**
  70. * This method displays the given quantity value on the screen.
  71. * @param numberOfCups
  72. */
  73. private void displayQuantity(int numberOfCups) {
  74. TextView quantityTextView = findViewById(R.id.quantity_text_view);
  75. quantityTextView.setText("" + numberOfCups);
  76. }
  77.  
  78.  
  79.  
  80. public void increment(View view) {
  81.  
  82. quantity++;
  83. displayQuantity(quantity);
  84. }
  85.  
  86. public void decrement(View view) {
  87.  
  88. quantity--;
  89. displayQuantity(quantity);
  90. }
  91.  
  92.  
  93. /**
  94. * This method displays the given text on the screen.
  95. */
  96. private void displayMessage(String message) {
  97. TextView orderSummaryTextView = findViewById(R.id.order_summary_text_view);
  98. orderSummaryTextView.setText(message);
  99. }
  100. }
Add Comment
Please, Sign In to add comment