Guest User

Untitled

a guest
Jun 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. package com.example.android.justjava;
  2.  
  3. import android.os.Bundle;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.view.View;
  6. import android.widget.TextView;
  7. import java.text.NumberFormat;
  8.  
  9. /**
  10. * This app displays an order form to order coffee.
  11. */
  12. public class MainActivity extends AppCompatActivity {
  13.  
  14. @Override
  15. protected void onCreate(Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  17. setContentView(R.layout.activity_main);
  18. }
  19.  
  20. /**
  21. * This method is called when the + button is clicked.
  22. */
  23. public void increment(View view) {
  24. int quantity = 2;
  25. quantity = 3;
  26. display(quantity);
  27. }
  28.  
  29. /**
  30. * This method is called when the - button is clicked.
  31. */
  32. public void decrement(View view) {
  33. int quantity = 1;
  34. display(quantity);
  35. }
  36.  
  37. /**
  38. * This method is called when the order button is clicked.
  39. */
  40. public void submitView view) {
  41. int coffeesNum = 2;
  42. display(coffeesNum);
  43. displayPrice(coffeesNum * 5);
  44. }
  45. /**
  46. * This method displays the given price on the screen.
  47. */
  48. private void displayPrice(int number) {
  49. TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
  50. priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
  51. }
  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. }
Add Comment
Please, Sign In to add comment