Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. package com.bignerdranch.android.tipcalculator;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.EditText;
  8. import android.widget.SeekBar;
  9. import android.widget.Spinner;
  10. import android.widget.TextView;
  11. import android.widget.Toast;
  12.  
  13. import java.util.ArrayList;
  14. import java.util.List;
  15.  
  16. import static android.widget.SeekBar.*;
  17. import static com.bignerdranch.android.tipcalculator.R.id.billEditText;
  18. import static com.bignerdranch.android.tipcalculator.R.id.calculateButton;
  19. import static com.bignerdranch.android.tipcalculator.R.id.percentTextView;
  20. import static com.bignerdranch.android.tipcalculator.R.id.splitSpinner;
  21. import static com.bignerdranch.android.tipcalculator.R.id.taxEditText;
  22. import static com.bignerdranch.android.tipcalculator.R.id.totalBillTextView;
  23. import static com.bignerdranch.android.tipcalculator.R.id.totalEditText;
  24. import static com.bignerdranch.android.tipcalculator.R.id.totalTipEditText;
  25.  
  26.  
  27. public class RestaurantActivity extends AppCompatActivity {
  28.  
  29. private EditText tax;
  30. private SeekBar tip;
  31. private Number MIN_TIP = .15;
  32. private EditText totalBillAmount;
  33. private Spinner peopleSplit;
  34. private EditText grandTotal;
  35. private EditText tipTotal;
  36. private TextView tipPercentLabel;
  37. private int tipPercentValue = 0;
  38. private EditText splitAmount;
  39. private Button calculateTips;
  40.  
  41. @Override
  42. protected void onCreate(Bundle savedInstanceState) {
  43. super.onCreate(savedInstanceState);
  44. setContentView(R.layout.activity_restaurant);
  45.  
  46. totalBillAmount = (EditText) findViewById(R.id.billEditText);
  47. tip = (SeekBar) findViewById(R.id.tipSeekBar);
  48. peopleSplit = (Spinner) findViewById(R.id.splitSpinner);
  49. tipPercentLabel = (TextView) findViewById(percentTextView);
  50. tax = (EditText) findViewById(R.id.taxEditText);
  51. splitAmount = (EditText) findViewById(R.id.splitAmountEditText);
  52.  
  53. grandTotal = (EditText) findViewById(R.id.totalEditText);
  54. tipTotal = (EditText) findViewById((int) totalTipEditText);
  55.  
  56. tip.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  57.  
  58. @Override
  59. public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
  60. tipPercentValue = (progress + 15);
  61. }
  62.  
  63. @Override
  64. public void onStartTrackingTouch(SeekBar seekBar) {
  65. }
  66.  
  67. @Override
  68. public void onStopTrackingTouch(SeekBar seekBar) {
  69. tipPercentLabel.setText(tipPercentValue + "%");
  70. }
  71. });
  72.  
  73.  
  74. calculateTips = (Button) findViewById(R.id.calculateButton);
  75. calculateTips.setOnClickListener(new View.OnClickListener() {
  76. @Override
  77. public void onClick(View v) {
  78.  
  79. if (totalBillAmount.getText().toString().equals("0") || totalBillAmount.getText().toString().isEmpty()) {
  80. Toast.makeText(RestaurantActivity.this, "Please input a value.", Toast.LENGTH_SHORT).show();
  81. return;
  82. }
  83. double totalBillAmount = Double.parseDouble(billEditText.getText().toString());
  84.  
  85. double tipTotalPercent = totalBillAmount * (tipPercentValue / 100);
  86. double tax = totalBillAmount * .07;
  87. double billTotalFinal = totalBillAmount + tipTotalPercent + tax;
  88. grandTotal.setText(String.valueOf(String.format("%.2f", totalEditText)));
  89. tipTotal.setText(String.valueOf(String.format("%.2f", totalTipEditText)));
  90.  
  91.  
  92. }
  93. });
  94. return view;
  95.  
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement