Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.niu.cs.z1761257.popnbooze;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TableLayout;
- import android.widget.TableRow;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.List;
- import com.parse.ParseGeoPoint;
- import com.parse.ParseObject;
- import com.parse.ParseQuery;
- public class MainActivity extends AppCompatActivity {
- //Declare Variables
- Double total = 0.0, MONEY = 0.0;
- TextView totalTV, moneyTV;
- EditText moneyET;
- static int COKEQTY = 3,PEPSIQTY = 1, SPRITEQTY = 5;
- static double COKEPRICE = 1.85,
- PEPSIPRICE = 1.99,
- SPRITEPRICE = 1.35;
- List<ParseObject> ob;
- private List<Drinks> drinkList = null;
- private ArrayList<Drinks> arraylist;
- Drinks drinkDetails;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- callfunction();
- this.arraylist = new ArrayList<Drinks>();
- this.arraylist.addAll(drinkList);
- totalTV = (TextView)findViewById(R.id.totalTV);
- moneyTV = (TextView)findViewById(R.id.moneyEditText);
- Display(1.85);
- }
- public void callfunction(){
- // Create the array
- drinkList = new ArrayList<Drinks>();
- try {
- // Locate the class table named "Country" in Parse.com
- ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
- "Drinks");
- query.orderByAscending("item_Name");
- ob = query.find();
- for (ParseObject drink : ob) {
- Drinks obj = new Drinks();
- obj.setItem_Name((String) drink.get("item_Name"));
- obj.setItem_Cost((Double) drink.get("item_Price"));
- obj.setItem_Qty((Double) drink.get("item_Qty"));
- obj.setItem_Calories((Double) drink.get("item_Calories"));
- drinkList.add(obj);
- }
- Toast.makeText(this,""+drinkList.size(),Toast.LENGTH_SHORT).show();
- } catch (Exception e) {
- // Log.e("Error", e.getMessage());
- e.printStackTrace();
- }
- }
- void Display( final Double ITEMPRICE){
- Toast.makeText(this,""+arraylist.size(), Toast.LENGTH_SHORT).show();
- TableLayout table = (TableLayout)findViewById(R.id.tableForButtons);
- for(int i= 0; i<drinkList.size();i++){
- TableRow tableRow = new TableRow(this);
- // tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
- // TableLayout.LayoutParams.MATCH_PARENT,10.0f));
- table.addView(tableRow);
- Button btn = new Button(this);
- tableRow.addView(btn);
- btn.setText(drinkList.get(i).getItem_Name());
- btn.setBackgroundResource(R.drawable.coke);
- btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(MONEY>ITEMPRICE && COKEQTY>0){
- total += ITEMPRICE;
- MONEY -= ITEMPRICE;
- COKEQTY--;
- moneyTV.setText("money: $"+new DecimalFormat("##.##").format(MONEY));
- totalTV.setText("Total: " + new DecimalFormat("##.##").format(total));
- }else if(COKEQTY<1){
- totalTV.setText("No Coke Stock");
- }else{
- double a = ITEMPRICE-MONEY;
- totalTV.setText("Need more $"+a);
- }
- }
- });
- // btn.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
- // TableRow.LayoutParams.MATCH_PARENT,1.0f))
- }
- }
- // public void insertCash(View view){
- //
- // moneyTV.setText("money: $"+new DecimalFormat("##.##").format(money));
- //
- // }
- public void bill20(View view){
- MONEY += 20;
- DisplayTotal();
- }
- public void bill10(View view){
- MONEY +=10;
- DisplayTotal();
- }
- public void bill5(View view){
- MONEY +=5;
- DisplayTotal();
- }
- public void bill1(View view){
- MONEY +=1;
- DisplayTotal();
- }
- public void billp25(View view){
- MONEY += 0.25;
- DisplayTotal();
- }
- public void DisplayTotal(){
- moneyTV.setText("Total: $"+new DecimalFormat("##.##").format(MONEY));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement