Guest User

Untitled

a guest
Mar 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. /**
  2. * IMPORTANT: Make sure you are using the correct package name.
  3. * This example uses the package name:
  4. * package com.example.android.justjava
  5. * If you get an error when copying this code into Android studio, update it to match teh package name found
  6. * in the project's AndroidManifest.xml file.
  7. **/
  8.  
  9. package com.example.android.justjava;
  10.  
  11.  
  12.  
  13. import android.os.Bundle;
  14. import android.support.v7.app.AppCompatActivity;
  15. import android.view.View;
  16. import android.widget.TextView;
  17.  
  18. import java.text.NumberFormat;
  19.  
  20. /**
  21. * This app displays an order form to order coffee.
  22. */
  23. public class MainActivity extends AppCompatActivity {
  24. int quantity = 0;
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.activity_main);
  29. }
  30.  
  31. /**
  32. * This method is called when the order button is clicked.
  33. */
  34. public void submitOrder(View view) {
  35. displayPrice(quantity*5);
  36. }
  37. /**
  38. * This method is called when the plus button is clicked.
  39. */
  40. public void increment(View view) {
  41. quantity = quantity + 1;
  42. display(quantity);
  43.  
  44.  
  45. }
  46. /**
  47. * This method is called when the mince button is clicked.
  48. */
  49. public void decrement(View view) {
  50. quantity = quantity - 1;
  51. display(quantity);
  52. }
  53. /**
  54. * This method displays the given quantity value on the screen.
  55. */
  56. private void display(int number) {
  57. TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
  58. quantityTextView.setText("" + number);
  59. }
  60.  
  61. /**
  62. * This method displays the given price on the screen.
  63. */
  64. private void displayPrice(int number) {
  65. TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
  66. priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
  67. }
  68. }
Add Comment
Please, Sign In to add comment