Advertisement
Guest User

Untitled

a guest
May 25th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. package edu.niu.cs.z1761257.popnbooze;
  2.  
  3. import android.content.Intent;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.TableLayout;
  11. import android.widget.TableRow;
  12. import android.widget.TextView;
  13. import android.widget.Toast;
  14.  
  15. import java.text.DecimalFormat;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18.  
  19. import com.parse.ParseGeoPoint;
  20. import com.parse.ParseObject;
  21. import com.parse.ParseQuery;
  22.  
  23. public class MainActivity extends AppCompatActivity {
  24.  
  25. //Declare Variables
  26. Double total = 0.0, MONEY = 0.0;
  27. TextView totalTV, moneyTV;
  28. EditText moneyET;
  29. static int COKEQTY = 3,PEPSIQTY = 1, SPRITEQTY = 5;
  30. static double COKEPRICE = 1.85,
  31. PEPSIPRICE = 1.99,
  32. SPRITEPRICE = 1.35;
  33.  
  34. List<ParseObject> ob;
  35. private List<Drinks> drinkList = null;
  36. private ArrayList<Drinks> arraylist;
  37.  
  38. Drinks drinkDetails;
  39.  
  40.  
  41. @Override
  42. protected void onCreate(Bundle savedInstanceState) {
  43. super.onCreate(savedInstanceState);
  44. setContentView(R.layout.activity_main);
  45. callfunction();
  46. this.arraylist = new ArrayList<Drinks>();
  47. this.arraylist.addAll(drinkList);
  48.  
  49. totalTV = (TextView)findViewById(R.id.totalTV);
  50. moneyTV = (TextView)findViewById(R.id.moneyEditText);
  51.  
  52. Display(1.85);
  53.  
  54.  
  55.  
  56. }
  57.  
  58.  
  59. public void callfunction(){
  60. // Create the array
  61. drinkList = new ArrayList<Drinks>();
  62. try {
  63. // Locate the class table named "Country" in Parse.com
  64. ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
  65. "Drinks");
  66. query.orderByAscending("item_Name");
  67. ob = query.find();
  68. for (ParseObject drink : ob) {
  69. Drinks obj = new Drinks();
  70. obj.setItem_Name((String) drink.get("item_Name"));
  71. obj.setItem_Cost((Double) drink.get("item_Price"));
  72. obj.setItem_Qty((Double) drink.get("item_Qty"));
  73. obj.setItem_Calories((Double) drink.get("item_Calories"));
  74.  
  75. drinkList.add(obj);
  76.  
  77. }
  78.  
  79. Toast.makeText(this,""+drinkList.size(),Toast.LENGTH_SHORT).show();
  80. } catch (Exception e) {
  81. // Log.e("Error", e.getMessage());
  82. e.printStackTrace();
  83. }
  84. }
  85.  
  86.  
  87.  
  88. void Display( final Double ITEMPRICE){
  89.  
  90.  
  91. Toast.makeText(this,""+arraylist.size(), Toast.LENGTH_SHORT).show();
  92.  
  93. TableLayout table = (TableLayout)findViewById(R.id.tableForButtons);
  94. for(int i= 0; i<drinkList.size();i++){
  95. TableRow tableRow = new TableRow(this);
  96. // tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
  97. // TableLayout.LayoutParams.MATCH_PARENT,10.0f));
  98.  
  99. table.addView(tableRow);
  100. Button btn = new Button(this);
  101. tableRow.addView(btn);
  102. btn.setText(drinkList.get(i).getItem_Name());
  103. btn.setBackgroundResource(R.drawable.coke);
  104.  
  105. btn.setOnClickListener(new View.OnClickListener() {
  106. @Override
  107. public void onClick(View v) {
  108. if(MONEY>ITEMPRICE && COKEQTY>0){
  109. total += ITEMPRICE;
  110. MONEY -= ITEMPRICE;
  111. COKEQTY--;
  112. moneyTV.setText("money: $"+new DecimalFormat("##.##").format(MONEY));
  113. totalTV.setText("Total: " + new DecimalFormat("##.##").format(total));
  114. }else if(COKEQTY<1){
  115. totalTV.setText("No Coke Stock");
  116. }else{
  117. double a = ITEMPRICE-MONEY;
  118. totalTV.setText("Need more $"+a);
  119. }
  120. }
  121. });
  122.  
  123.  
  124.  
  125.  
  126.  
  127. // btn.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
  128. // TableRow.LayoutParams.MATCH_PARENT,1.0f))
  129. }
  130.  
  131. }
  132.  
  133. // public void insertCash(View view){
  134. //
  135. // moneyTV.setText("money: $"+new DecimalFormat("##.##").format(money));
  136. //
  137. // }
  138.  
  139. public void bill20(View view){
  140. MONEY += 20;
  141. DisplayTotal();
  142. }
  143.  
  144. public void bill10(View view){
  145. MONEY +=10;
  146. DisplayTotal();
  147. }
  148.  
  149. public void bill5(View view){
  150. MONEY +=5;
  151. DisplayTotal();
  152. }
  153.  
  154. public void bill1(View view){
  155. MONEY +=1;
  156. DisplayTotal();
  157. }
  158.  
  159. public void billp25(View view){
  160. MONEY += 0.25;
  161. DisplayTotal();
  162. }
  163.  
  164. public void DisplayTotal(){
  165. moneyTV.setText("Total: $"+new DecimalFormat("##.##").format(MONEY));
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement